From d577257bd5c9dc6f1e7cfef67d7eb4a825e12fbf Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Mon, 20 Feb 2017 16:20:20 +0100 Subject: [PATCH] rename ProviderHelper -> DatabaseInteractor --- .../keychain/TestHelpers.java | 7 +- .../keychain/actions/CustomActions.java | 6 +- .../keychain/operations/BackupOperation.java | 14 +-- .../keychain/operations/BaseOperation.java | 16 ++-- .../operations/BenchmarkOperation.java | 11 ++- .../keychain/operations/CertifyOperation.java | 20 ++--- .../operations/ChangeUnlockOperation.java | 12 +-- .../operations/ConsolidateOperation.java | 10 +-- .../keychain/operations/DeleteOperation.java | 10 +-- .../keychain/operations/EditKeyOperation.java | 15 ++-- .../keychain/operations/ImportOperation.java | 24 +++--- .../operations/InputDataOperation.java | 10 +-- .../KeybaseVerificationOperation.java | 8 +- .../operations/PromoteKeyOperation.java | 12 +-- .../keychain/operations/RevokeOperation.java | 12 +-- .../operations/SignEncryptOperation.java | 10 +-- .../keychain/operations/UploadOperation.java | 10 +-- .../keychain/pgp/CanonicalizedSecretKey.java | 4 +- .../pgp/OpenPgpSignatureResultBuilder.java | 12 +-- .../pgp/PgpDecryptVerifyOperation.java | 18 ++-- .../keychain/pgp/PgpSignEncryptOperation.java | 20 ++--- .../keychain/pgp/PgpSignatureChecker.java | 18 ++-- .../provider/CachedPublicKeyRing.java | 86 +++++++++---------- ...derHelper.java => DatabaseInteractor.java} | 12 +-- .../keychain/remote/OpenPgpService.java | 22 ++--- .../ui/RequestKeyPermissionPresenter.java | 16 ++-- .../keychain/service/KeychainService.java | 32 +++---- .../service/KeyserverSyncAdapterService.java | 6 +- .../service/PassphraseCacheService.java | 12 +-- .../ui/CertifyFingerprintFragment.java | 4 +- .../keychain/ui/CertifyKeyFragment.java | 16 +--- .../keychain/ui/CreateKeyActivity.java | 4 +- .../keychain/ui/CreateKeyFinalFragment.java | 6 +- .../keychain/ui/DecryptFragment.java | 4 +- .../keychain/ui/DeleteKeyDialogActivity.java | 20 ++--- .../keychain/ui/EditIdentitiesFragment.java | 6 +- .../keychain/ui/EditKeyFragment.java | 6 +- .../ui/EncryptModeAsymmetricFragment.java | 13 ++- .../keychain/ui/KeyListFragment.java | 6 +- .../keychain/ui/PassphraseDialogActivity.java | 13 ++- .../keychain/ui/QrCodeViewActivity.java | 10 +-- .../keychain/ui/SafeSlingerActivity.java | 8 +- .../ui/SecurityTokenOperationActivity.java | 14 +-- .../keychain/ui/ViewCertActivity.java | 6 +- .../keychain/ui/ViewKeyActivity.java | 30 +++---- .../keychain/ui/ViewKeyAdvActivity.java | 8 +- .../keychain/ui/ViewKeyAdvShareFragment.java | 16 ++-- .../ui/adapter/ImportKeysAdapter.java | 12 +-- .../ui/base/BaseSecurityTokenActivity.java | 4 +- .../keychain/ui/linked/LinkedIdWizard.java | 4 +- .../keychain/util/NfcHelper.java | 15 ++-- .../operations/BackupOperationTest.java | 16 ++-- .../operations/BenchmarkOperationTest.java | 4 +- .../operations/CertifyOperationTest.java | 26 +++--- .../operations/PromoteKeyOperationTest.java | 18 ++-- .../keychain/pgp/InputDataOperationTest.java | 6 +- .../keychain/pgp/PgpEncryptDecryptTest.java | 60 ++++++------- ...ava => DatabaseInteractorKeyringTest.java} | 2 +- ...t.java => DatabaseInteractorSaveTest.java} | 44 +++++----- .../keychain/provider/InteropTest.java | 2 +- .../remote/KeychainExternalProviderTest.java | 14 +-- ...rStub.java => DatabaseInteractorStub.java} | 6 +- .../support/KeyringTestingHelper.java | 18 ++-- 63 files changed, 439 insertions(+), 467 deletions(-) rename OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/{ProviderHelper.java => DatabaseInteractor.java} (99%) rename OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/{ProviderHelperKeyringTest.java => DatabaseInteractorKeyringTest.java} (98%) rename OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/{ProviderHelperSaveTest.java => DatabaseInteractorSaveTest.java} (83%) rename OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/{ProviderHelperStub.java => DatabaseInteractorStub.java} (86%) diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java index 29d6c7262..6d957e6fc 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/TestHelpers.java @@ -31,18 +31,15 @@ import android.content.Context; import android.support.annotation.StringRes; import android.support.test.espresso.UiController; import android.support.test.espresso.ViewAction; -import android.support.test.espresso.base.DefaultFailureHandler; import android.support.test.espresso.matcher.ViewMatchers; import android.view.View; import com.nispok.snackbar.Snackbar; -import com.tokenautocomplete.TokenCompleteTextView; -import org.hamcrest.CoreMatchers; import org.hamcrest.Matcher; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; import org.sufficientlysecure.keychain.provider.KeychainDatabase; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.ProgressScaler; @@ -100,7 +97,7 @@ public class TestHelpers { IteratorWithIOThrow stream = UncachedKeyRing.fromStream( getInstrumentation().getContext().getAssets().open(name)); - ProviderHelper helper = new ProviderHelper(context); + DatabaseInteractor helper = new DatabaseInteractor(context); while(stream.hasNext()) { UncachedKeyRing ring = stream.next(); if (ring.isSecret()) { diff --git a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java index 75197ac9e..ee532ab92 100644 --- a/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java +++ b/OpenKeychain/src/androidTest/java/org/sufficientlysecure/keychain/actions/CustomActions.java @@ -22,14 +22,12 @@ package org.sufficientlysecure.keychain.actions; import android.support.test.espresso.UiController; import android.support.test.espresso.ViewAction; import android.support.test.espresso.matcher.ViewMatchers; -import android.support.v4.view.GravityCompat; -import android.support.v4.widget.DrawerLayout; import android.view.View; import com.tokenautocomplete.TokenCompleteTextView; import org.hamcrest.Matcher; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter; import static android.support.test.InstrumentationRegistry.getTargetContext; @@ -39,7 +37,7 @@ public abstract class CustomActions { public static ViewAction tokenEncryptViewAddToken(long keyId) throws Exception { CanonicalizedPublicKeyRing ring = - new ProviderHelper(getTargetContext()).getCanonicalizedPublicKeyRing(keyId); + new DatabaseInteractor(getTargetContext()).getCanonicalizedPublicKeyRing(keyId); final Object item = new KeyAdapter.KeyItem(ring); return new ViewAction() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java index 0895e5251..f8568ee3c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BackupOperation.java @@ -53,7 +53,7 @@ import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -86,14 +86,14 @@ public class BackupOperation extends BaseOperation { private static final int INDEX_SECKEY_DATA = 2; private static final int INDEX_HAS_ANY_SECRET = 3; - public BackupOperation(Context context, ProviderHelper providerHelper, Progressable + public BackupOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { - super(context, providerHelper, progressable); + super(context, databaseInteractor, progressable); } - public BackupOperation(Context context, ProviderHelper providerHelper, + public BackupOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } @NonNull @@ -170,7 +170,7 @@ public class BackupOperation extends BaseOperation { private PgpSignEncryptResult encryptBackupData(@NonNull BackupKeyringParcel backupInput, @NonNull CryptoInputParcel cryptoInput, @Nullable OutputStream outputStream, Uri plainUri, long exportedDataSize) throws FileNotFoundException { - PgpSignEncryptOperation signEncryptOperation = new PgpSignEncryptOperation(mContext, mProviderHelper, mProgressable, mCancelled); + PgpSignEncryptOperation signEncryptOperation = new PgpSignEncryptOperation(mContext, mDatabaseInteractor, mProgressable, mCancelled); PgpSignEncryptData data = new PgpSignEncryptData(); data.setSymmetricPassphrase(cryptoInput.getPassphrase()); @@ -326,7 +326,7 @@ public class BackupOperation extends BaseOperation { + " IN (" + placeholders + ")"; } - return mProviderHelper.getContentResolver().query( + return mDatabaseInteractor.getContentResolver().query( KeyRings.buildUnifiedKeyRingsUri(), PROJECTION, selection, selectionArgs, Tables.KEYS + "." + KeyRings.MASTER_KEY_ID ); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java index 99d1768b1..ee21eb007 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BaseOperation.java @@ -26,8 +26,8 @@ import org.sufficientlysecure.keychain.Constants.key; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.PassphraseCacheInterface; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Passphrase; @@ -40,7 +40,7 @@ public abstract class BaseOperation implements Passphrase final public Progressable mProgressable; final public AtomicBoolean mCancelled; - final public ProviderHelper mProviderHelper; + final public DatabaseInteractor mDatabaseInteractor; /** An abstract base class for all *Operation classes. It provides a number * of common methods for progress, cancellation and passphrase cache handling. @@ -64,18 +64,18 @@ public abstract class BaseOperation implements Passphrase * if there is no prefix it is considered Android-related. * */ - public BaseOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { + public BaseOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { this.mContext = context; this.mProgressable = progressable; - this.mProviderHelper = providerHelper; + this.mDatabaseInteractor = databaseInteractor; mCancelled = null; } - public BaseOperation(Context context, ProviderHelper providerHelper, + public BaseOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { mContext = context; mProgressable = progressable; - mProviderHelper = providerHelper; + mDatabaseInteractor = databaseInteractor; mCancelled = cancelled; } @@ -114,7 +114,7 @@ public abstract class BaseOperation implements Passphrase public Passphrase getCachedPassphrase(long subKeyId) throws NoSecretKeyException { try { if (subKeyId != key.symmetric) { - long masterKeyId = mProviderHelper.getMasterKeyId(subKeyId); + long masterKeyId = mDatabaseInteractor.getMasterKeyId(subKeyId); return getCachedPassphrase(masterKeyId, subKeyId); } return getCachedPassphrase(key.symmetric, key.symmetric); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java index a179fa66a..ece2d5487 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/BenchmarkOperation.java @@ -41,12 +41,11 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.Operat import org.sufficientlysecure.keychain.operations.results.SignEncryptResult; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; -import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants; import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants.OpenKeychainSymmetricKeyAlgorithmTags; import org.sufficientlysecure.keychain.pgp.PgpSignEncryptData; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.BenchmarkInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; @@ -56,9 +55,9 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; public class BenchmarkOperation extends BaseOperation { - public BenchmarkOperation(Context context, ProviderHelper providerHelper, Progressable + public BenchmarkOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { - super(context, providerHelper, progressable); + super(context, databaseInteractor, progressable); } @NonNull @@ -82,7 +81,7 @@ public class BenchmarkOperation extends BaseOperation { int i = 0; do { SignEncryptOperation op = - new SignEncryptOperation(mContext, mProviderHelper, + new SignEncryptOperation(mContext, mDatabaseInteractor, new ProgressScaler(mProgressable, i*(50/numRepeats), (i+1)*(50/numRepeats), 100), mCancelled); PgpSignEncryptData data = new PgpSignEncryptData(); data.setSymmetricPassphrase(passphrase); @@ -104,7 +103,7 @@ public class BenchmarkOperation extends BaseOperation { do { DecryptVerifyResult decryptResult; PgpDecryptVerifyOperation op = - new PgpDecryptVerifyOperation(mContext, mProviderHelper, + new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, new ProgressScaler(mProgressable, 50 +i*(50/numRepeats), 50 +(i+1)*(50/numRepeats), 100)); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(encryptResult.getResultBytes()); input.setAllowSymmetricDecryption(true); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java index b4b27f7ab..17d30f75f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java @@ -39,8 +39,8 @@ import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; @@ -62,9 +62,9 @@ import org.sufficientlysecure.keychain.util.Passphrase; */ public class CertifyOperation extends BaseOperation { - public CertifyOperation(Context context, ProviderHelper providerHelper, Progressable progressable, AtomicBoolean + public CertifyOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } @NonNull @@ -81,7 +81,7 @@ public class CertifyOperation extends BaseOperation { log.add(LogType.MSG_CRT_MASTER_FETCH, 1); - CachedPublicKeyRing cachedPublicKeyRing = mProviderHelper.getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing cachedPublicKeyRing = mDatabaseInteractor.getCachedPublicKeyRing(masterKeyId); Passphrase passphrase; switch (cachedPublicKeyRing.getSecretKeyType(masterKeyId)) { @@ -121,7 +121,7 @@ public class CertifyOperation extends BaseOperation { // Get actual secret key CanonicalizedSecretKeyRing secretKeyRing = - mProviderHelper.getCanonicalizedSecretKeyRing(parcel.mMasterKeyId); + mDatabaseInteractor.getCanonicalizedSecretKeyRing(parcel.mMasterKeyId); certificationKey = secretKeyRing.getSecretKey(); log.add(LogType.MSG_CRT_UNLOCK, 1); @@ -165,7 +165,7 @@ public class CertifyOperation extends BaseOperation { } CanonicalizedPublicKeyRing publicRing = - mProviderHelper.getCanonicalizedPublicKeyRing(action.mMasterKeyId); + mDatabaseInteractor.getCanonicalizedPublicKeyRing(action.mMasterKeyId); PgpCertifyOperation op = new PgpCertifyOperation(); PgpCertifyResult result = op.certify(certificationKey, publicRing, @@ -206,7 +206,7 @@ public class CertifyOperation extends BaseOperation { // these variables are used inside the following loop, but they need to be created only once UploadOperation uploadOperation = null; if (parcel.keyServerUri != null) { - uploadOperation = new UploadOperation(mContext, mProviderHelper, mProgressable, mCancelled); + uploadOperation = new UploadOperation(mContext, mDatabaseInteractor, mProgressable, mCancelled); } // Write all certified keys into the database @@ -222,8 +222,8 @@ public class CertifyOperation extends BaseOperation { 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); + mDatabaseInteractor.clearLog(); + SaveKeyringResult result = mDatabaseInteractor.savePublicKeyRing(certifiedKey); if (uploadOperation != null) { UploadKeyringParcel uploadInput = diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java index f9ae13b1a..4cf76e5a3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ChangeUnlockOperation.java @@ -29,7 +29,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -38,8 +38,8 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; public class ChangeUnlockOperation extends BaseOperation { - public ChangeUnlockOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { - super(context, providerHelper, progressable); + public ChangeUnlockOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + super(context, databaseInteractor, progressable); } @NonNull @@ -63,7 +63,7 @@ public class ChangeUnlockOperation extends BaseOperation { KeyFormattingUtils.convertKeyIdToHex(unlockParcel.mMasterKeyId)); CanonicalizedSecretKeyRing secRing = - mProviderHelper.getCanonicalizedSecretKeyRing(unlockParcel.mMasterKeyId); + mDatabaseInteractor.getCanonicalizedSecretKeyRing(unlockParcel.mMasterKeyId); modifyResult = keyOperations.modifyKeyRingPassphrase(secRing, cryptoInput, unlockParcel); if (modifyResult.isPending()) { @@ -71,7 +71,7 @@ public class ChangeUnlockOperation extends BaseOperation { log.add(modifyResult, 1); return new EditKeyResult(log, modifyResult); } - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { log.add(OperationResult.LogType.MSG_ED_ERROR_KEY_NOT_FOUND, 2); return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null); } @@ -90,7 +90,7 @@ public class ChangeUnlockOperation extends BaseOperation { // It's a success, so this must be non-null now UncachedKeyRing ring = modifyResult.getRing(); - SaveKeyringResult saveResult = mProviderHelper + SaveKeyringResult saveResult = mDatabaseInteractor .saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 70, 95, 100)); log.add(saveResult, 1); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java index 782cd6800..1142b085e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ConsolidateOperation.java @@ -24,15 +24,15 @@ import android.support.annotation.NonNull; import org.sufficientlysecure.keychain.operations.results.ConsolidateResult; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ConsolidateInputParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; public class ConsolidateOperation extends BaseOperation { - public ConsolidateOperation(Context context, ProviderHelper providerHelper, Progressable + public ConsolidateOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { - super(context, providerHelper, progressable); + super(context, databaseInteractor, progressable); } @NonNull @@ -40,9 +40,9 @@ public class ConsolidateOperation extends BaseOperation public ConsolidateResult execute(ConsolidateInputParcel consolidateInputParcel, CryptoInputParcel cryptoInputParcel) { if (consolidateInputParcel.mConsolidateRecovery) { - return mProviderHelper.consolidateDatabaseStep2(mProgressable); + return mDatabaseInteractor.consolidateDatabaseStep2(mProgressable); } else { - return mProviderHelper.consolidateDatabaseStep1(mProgressable); + return mDatabaseInteractor.consolidateDatabaseStep1(mProgressable); } } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java index 8227fea02..e86591d6b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/DeleteOperation.java @@ -27,7 +27,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.DeleteKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -43,8 +43,8 @@ import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; */ public class DeleteOperation extends BaseOperation { - public DeleteOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { - super(context, providerHelper, progressable); + public DeleteOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + super(context, databaseInteractor, progressable); } @NonNull @@ -81,7 +81,7 @@ public class DeleteOperation extends BaseOperation { cancelled = true; break; } - int count = mProviderHelper.getContentResolver().delete( + int count = mDatabaseInteractor.getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(masterKeyId), null, null ); if (count > 0) { @@ -95,7 +95,7 @@ public class DeleteOperation extends BaseOperation { if (isSecret && success > 0) { log.add(LogType.MSG_DEL_CONSOLIDATE, 1); - ConsolidateResult sub = mProviderHelper.consolidateDatabaseStep1(mProgressable); + ConsolidateResult sub = mDatabaseInteractor.consolidateDatabaseStep1(mProgressable); log.add(sub, 2); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java index 8af2fdc67..ab4e95fcc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/EditKeyOperation.java @@ -35,10 +35,9 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; -import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -58,9 +57,9 @@ import org.sufficientlysecure.keychain.util.ProgressScaler; */ public class EditKeyOperation extends BaseOperation { - public EditKeyOperation(Context context, ProviderHelper providerHelper, + public EditKeyOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } /** @@ -95,7 +94,7 @@ public class EditKeyOperation extends BaseOperation { log.add(LogType.MSG_ED_FETCHING, 1, KeyFormattingUtils.convertKeyIdToHex(saveParcel.mMasterKeyId)); CanonicalizedSecretKeyRing secRing = - mProviderHelper.getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId); + mDatabaseInteractor.getCanonicalizedSecretKeyRing(saveParcel.mMasterKeyId); modifyResult = keyOperations.modifySecretKeyRing(secRing, cryptoInput, saveParcel); if (modifyResult.isPending()) { @@ -148,7 +147,7 @@ public class EditKeyOperation extends BaseOperation { new UploadKeyringParcel(saveParcel.getUploadKeyserver(), keyringBytes); UploadResult uploadResult = - new UploadOperation(mContext, mProviderHelper, mProgressable, mCancelled) + new UploadOperation(mContext, mDatabaseInteractor, mProgressable, mCancelled) .execute(exportKeyringParcel, cryptoInput); log.add(uploadResult, 2); @@ -162,7 +161,7 @@ public class EditKeyOperation extends BaseOperation { } // Save the new keyring. - SaveKeyringResult saveResult = mProviderHelper + SaveKeyringResult saveResult = mDatabaseInteractor .saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 60, 95, 100)); log.add(saveResult, 1); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java index d465bde04..4757d7874 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportOperation.java @@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; 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.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ContactSyncAdapterService; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -86,14 +86,14 @@ public class ImportOperation extends BaseOperation { public static final String CACHE_FILE_NAME = "key_import.pcl"; - public ImportOperation(Context context, ProviderHelper providerHelper, Progressable + public ImportOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { - super(context, providerHelper, progressable); + super(context, databaseInteractor, progressable); } - public ImportOperation(Context context, ProviderHelper providerHelper, + public ImportOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } // Overloaded functions for using progressable supplied in constructor during import @@ -314,15 +314,15 @@ public class ImportOperation extends BaseOperation { SaveKeyringResult result; // synchronizing prevents https://github.com/open-keychain/open-keychain/issues/1221 // and https://github.com/open-keychain/open-keychain/issues/1480 - synchronized (mProviderHelper) { - mProviderHelper.clearLog(); + synchronized (mDatabaseInteractor) { + mDatabaseInteractor.clearLog(); ProgressScaler progressScaler = new ProgressScaler(progressable, (int) (position * progSteps), (int) ((position + 1) * progSteps), 100); if (key.isSecret()) { - result = mProviderHelper.saveSecretKeyRing(key, progressScaler, + result = mDatabaseInteractor.saveSecretKeyRing(key, progressScaler, canKeyRings, skipSave); } else { - result = mProviderHelper.savePublicKeyRing(key, progressScaler, + result = mDatabaseInteractor.savePublicKeyRing(key, progressScaler, entry.mExpectedFingerprint, canKeyRings, skipSave); } } @@ -343,7 +343,7 @@ public class ImportOperation extends BaseOperation { // synonymous to isDownloadFromKeyserver. // If no byte data was supplied, import from keyserver took place // this prevents file imports being noted as keyserver imports - mProviderHelper.renewKeyLastUpdatedTime(key.getMasterKeyId(), + mDatabaseInteractor.renewKeyLastUpdatedTime(key.getMasterKeyId(), GregorianCalendar.getInstance().getTimeInMillis(), TimeUnit.MILLISECONDS); } @@ -365,8 +365,8 @@ public class ImportOperation extends BaseOperation { if (!skipSave && (secret > 0)) { setPreventCancel(); ConsolidateResult result; - synchronized (mProviderHelper) { - result = mProviderHelper.consolidateDatabaseStep1(progressable); + synchronized (mDatabaseInteractor) { + result = mDatabaseInteractor.consolidateDatabaseStep1(progressable); } log.add(result, 1); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java index 68220857b..2c62778b8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java @@ -50,7 +50,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.Operat import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.InputDataParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -71,8 +71,8 @@ public class InputDataOperation extends BaseOperation { private final byte[] buf = new byte[256]; - public InputDataOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { - super(context, providerHelper, progressable); + public InputDataOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + super(context, databaseInteractor, progressable); } Uri mSignedDataUri; @@ -101,7 +101,7 @@ public class InputDataOperation extends BaseOperation { log.add(LogType.MSG_DATA_OPENPGP, 1); PgpDecryptVerifyOperation op = - new PgpDecryptVerifyOperation(mContext, mProviderHelper, mProgressable); + new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, mProgressable); decryptInput.setInputUri(input.getInputUri()); @@ -269,7 +269,7 @@ public class InputDataOperation extends BaseOperation { decryptInput.setDetachedSignature(detachedSig.toByteArray()); PgpDecryptVerifyOperation op = - new PgpDecryptVerifyOperation(mContext, mProviderHelper, mProgressable); + new PgpDecryptVerifyOperation(mContext, mDatabaseInteractor, mProgressable); DecryptVerifyResult verifyResult = op.execute(decryptInput, cryptoInput); log.addByMerge(verifyResult, 4); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java index 2bcb84592..4f4a8b0db 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/KeybaseVerificationOperation.java @@ -36,7 +36,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.Progressable; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.KeybaseVerificationParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -59,9 +59,9 @@ import de.measite.minidns.record.TXT; public class KeybaseVerificationOperation extends BaseOperation { - public KeybaseVerificationOperation(Context context, ProviderHelper providerHelper, + public KeybaseVerificationOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { - super(context, providerHelper, progressable); + super(context, databaseInteractor, progressable); } @NonNull @@ -147,7 +147,7 @@ public class KeybaseVerificationOperation extends BaseOperation { - public PromoteKeyOperation(Context context, ProviderHelper providerHelper, + public PromoteKeyOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } @NonNull @@ -70,7 +70,7 @@ public class PromoteKeyOperation extends BaseOperation { log.add(LogType.MSG_PR_FETCHING, 1, KeyFormattingUtils.convertKeyIdToHex(promoteKeyringParcel.mKeyRingId)); CanonicalizedPublicKeyRing pubRing = - mProviderHelper.getCanonicalizedPublicKeyRing(promoteKeyringParcel.mKeyRingId); + mDatabaseInteractor.getCanonicalizedPublicKeyRing(promoteKeyringParcel.mKeyRingId); if (promoteKeyringParcel.mSubKeyIds == null) { log.add(LogType.MSG_PR_ALL, 1); @@ -114,7 +114,7 @@ public class PromoteKeyOperation extends BaseOperation { setPreventCancel(); // Save the new keyring. - SaveKeyringResult saveResult = mProviderHelper + SaveKeyringResult saveResult = mDatabaseInteractor .saveSecretKeyRing(promotedRing, new ProgressScaler(mProgressable, 60, 95, 100)); log.add(saveResult, 1); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java index 3e787560a..920efb1ef 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/RevokeOperation.java @@ -32,7 +32,7 @@ import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.RevokeKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -41,8 +41,8 @@ import org.sufficientlysecure.keychain.util.Log; public class RevokeOperation extends BaseOperation { - public RevokeOperation(Context context, ProviderHelper providerHelper, Progressable progressable) { - super(context, providerHelper, progressable); + public RevokeOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable) { + super(context, databaseInteractor, progressable); } @NonNull @@ -62,7 +62,7 @@ public class RevokeOperation extends BaseOperation { try { Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(masterKeyId); - CachedPublicKeyRing keyRing = mProviderHelper.getCachedPublicKeyRing(secretUri); + CachedPublicKeyRing keyRing = mDatabaseInteractor.getCachedPublicKeyRing(secretUri); // check if this is a master secret key we can work with switch (keyRing.getSecretKeyType(masterKeyId)) { @@ -81,7 +81,7 @@ public class RevokeOperation extends BaseOperation { saveKeyringParcel.mRevokeSubKeys.add(masterKeyId); EditKeyResult revokeAndUploadResult = new EditKeyOperation(mContext, - mProviderHelper, mProgressable, mCancelled).execute(saveKeyringParcel, cryptoInputParcel); + mDatabaseInteractor, mProgressable, mCancelled).execute(saveKeyringParcel, cryptoInputParcel); if (revokeAndUploadResult.isPending()) { return revokeAndUploadResult; @@ -97,7 +97,7 @@ public class RevokeOperation extends BaseOperation { return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId); } - } catch (PgpKeyNotFoundException | ProviderHelper.NotFoundException e) { + } catch (PgpKeyNotFoundException | DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "could not find key to revoke", e); log.add(OperationResult.LogType.MSG_REVOKE_ERROR_KEY_FAIL, 1); return new RevokeResult(RevokeResult.RESULT_ERROR, log, masterKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java index dedc03553..fb5c941fb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/SignEncryptOperation.java @@ -33,7 +33,7 @@ import org.sufficientlysecure.keychain.pgp.PgpSignEncryptOperation; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.SecurityTokenSignOperationsBuilder; @@ -55,9 +55,9 @@ import java.util.concurrent.atomic.AtomicBoolean; */ public class SignEncryptOperation extends BaseOperation { - public SignEncryptOperation(Context context, ProviderHelper providerHelper, + public SignEncryptOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } @@ -81,7 +81,7 @@ public class SignEncryptOperation extends BaseOperation { if (data.getSignatureMasterKeyId() != Constants.key.none && data.getSignatureSubKeyId() == null) { try { - long signKeyId = mProviderHelper.getCachedPublicKeyRing( + long signKeyId = mDatabaseInteractor.getCachedPublicKeyRing( data.getSignatureMasterKeyId()).getSecretSignId(); data.setSignatureSubKeyId(signKeyId); } catch (PgpKeyNotFoundException e) { @@ -96,7 +96,7 @@ public class SignEncryptOperation extends BaseOperation { return new SignEncryptResult(SignEncryptResult.RESULT_CANCELLED, log, results); } - PgpSignEncryptOperation op = new PgpSignEncryptOperation(mContext, mProviderHelper, + PgpSignEncryptOperation op = new PgpSignEncryptOperation(mContext, mDatabaseInteractor, new ProgressScaler(mProgressable, 100 * count / total, 100 * ++count / total, 100), mCancelled); PgpSignEncryptInputParcel inputParcel = new PgpSignEncryptInputParcel(input.getData()); if (inputBytes != null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java index 9e60f22e0..bc75d0ae7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/UploadOperation.java @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; 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.DatabaseInteractor; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -58,9 +58,9 @@ import java.util.concurrent.atomic.AtomicBoolean; */ public class UploadOperation extends BaseOperation { - public UploadOperation(Context context, ProviderHelper providerHelper, + public UploadOperation(Context context, DatabaseInteractor databaseInteractor, Progressable progressable, AtomicBoolean cancelled) { - super(context, providerHelper, progressable, cancelled); + super(context, databaseInteractor, progressable, cancelled); } @NonNull @@ -120,7 +120,7 @@ public class UploadOperation extends BaseOperation { if (hasMasterKeyId) { log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(uploadInput.mMasterKeyId)); - return mProviderHelper.getCanonicalizedPublicKeyRing(uploadInput.mMasterKeyId); + return mDatabaseInteractor.getCanonicalizedPublicKeyRing(uploadInput.mMasterKeyId); } CanonicalizedKeyRing canonicalizedRing = @@ -132,7 +132,7 @@ public class UploadOperation extends BaseOperation { log.add(LogType.MSG_UPLOAD_KEY, 0, KeyFormattingUtils.convertKeyIdToHex(canonicalizedRing.getMasterKeyId())); return (CanonicalizedPublicKeyRing) canonicalizedRing; - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { log.add(LogType.MSG_UPLOAD_ERROR_NOT_FOUND, 1); return null; } catch (IOException | PgpGeneralException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java index 29ea17e64..ee8a2b050 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedSecretKey.java @@ -47,7 +47,7 @@ import org.bouncycastle.openpgp.operator.jcajce.SessionKeySecretKeyDecryptorBuil import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; @@ -127,7 +127,7 @@ public class CanonicalizedSecretKey extends CanonicalizedPublicKey { * passphrase in the process. * * This method can potentially take a LONG time (i.e. seconds), so it should only - * ever be called by {@link ProviderHelper} for the purpose of caching its output + * ever be called by {@link DatabaseInteractor} for the purpose of caching its output * in the database. */ public SecretKeyType getSecretKeyTypeSuperExpensive() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java index e327180c3..34fdc20c3 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/OpenPgpSignatureResultBuilder.java @@ -27,8 +27,8 @@ import org.openintents.openpgp.util.OpenPgpUtils; import org.openintents.openpgp.util.OpenPgpUtils.UserId; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.util.Log; /** @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.util.Log; */ public class OpenPgpSignatureResultBuilder { // injected - private final ProviderHelper mProviderHelper; + private final DatabaseInteractor mDatabaseInteractor; // OpenPgpSignatureResult private String mPrimaryUserId; @@ -57,8 +57,8 @@ public class OpenPgpSignatureResultBuilder { private String mSenderAddress; private Date mSignatureTimestamp; - public OpenPgpSignatureResultBuilder(ProviderHelper providerHelper) { - this.mProviderHelper = providerHelper; + public OpenPgpSignatureResultBuilder(DatabaseInteractor databaseInteractor) { + this.mDatabaseInteractor = databaseInteractor; } public void setPrimaryUserId(String userId) { @@ -127,7 +127,7 @@ public class OpenPgpSignatureResultBuilder { try { ArrayList allUserIds = signingRing.getUnorderedUserIds(); - ArrayList confirmedUserIds = mProviderHelper.getConfirmedUserIds(signingRing.getMasterKeyId()); + ArrayList confirmedUserIds = mDatabaseInteractor.getConfirmedUserIds(signingRing.getMasterKeyId()); setUserIds(allUserIds, confirmedUserIds); if (mSenderAddress != null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java index 88334e9af..b7662b44e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpDecryptVerifyOperation.java @@ -72,7 +72,7 @@ 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.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -87,8 +87,8 @@ public class PgpDecryptVerifyOperation extends BaseOperation encryptSubKeyIds = keyRing.getEncryptIds(); for (Long subKeyId : encryptSubKeyIds) { @@ -356,7 +356,7 @@ public class PgpSignEncryptOperation extends BaseOperation 0; - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -158,11 +158,11 @@ public class CachedPublicKeyRing extends KeyRing { @Override public boolean canCertify() throws PgpKeyNotFoundException { try { - Object data = mProviderHelper.getGenericData(mUri, + Object data = mDatabaseInteractor.getGenericData(mUri, KeychainContract.KeyRings.HAS_CERTIFY, - ProviderHelper.FIELD_TYPE_NULL); + DatabaseInteractor.FIELD_TYPE_NULL); return !((Boolean) data); - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -170,11 +170,11 @@ public class CachedPublicKeyRing extends KeyRing { @Override public long getEncryptId() throws PgpKeyNotFoundException { try { - Object data = mProviderHelper.getGenericData(mUri, + Object data = mDatabaseInteractor.getGenericData(mUri, KeyRings.HAS_ENCRYPT, - ProviderHelper.FIELD_TYPE_INTEGER); + DatabaseInteractor.FIELD_TYPE_INTEGER); return (Long) data; - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -192,11 +192,11 @@ public class CachedPublicKeyRing extends KeyRing { */ public long getSecretSignId() throws PgpKeyNotFoundException { try { - Object data = mProviderHelper.getGenericData(mUri, + Object data = mDatabaseInteractor.getGenericData(mUri, KeyRings.HAS_SIGN, - ProviderHelper.FIELD_TYPE_INTEGER); + DatabaseInteractor.FIELD_TYPE_INTEGER); return (Long) data; - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } @@ -204,35 +204,35 @@ public class CachedPublicKeyRing extends KeyRing { @Override public int getVerified() throws PgpKeyNotFoundException { try { - Object data = mProviderHelper.getGenericData(mUri, + Object data = mDatabaseInteractor.getGenericData(mUri, KeychainContract.KeyRings.VERIFIED, - ProviderHelper.FIELD_TYPE_INTEGER); + DatabaseInteractor.FIELD_TYPE_INTEGER); return ((Long) data).intValue(); - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } public boolean hasAnySecret() throws PgpKeyNotFoundException { try { - Object data = mProviderHelper.getGenericData(mUri, + Object data = mDatabaseInteractor.getGenericData(mUri, KeychainContract.KeyRings.HAS_ANY_SECRET, - ProviderHelper.FIELD_TYPE_INTEGER); + DatabaseInteractor.FIELD_TYPE_INTEGER); return (Long) data > 0; - } catch(ProviderHelper.NotFoundException e) { + } catch(DatabaseInteractor.NotFoundException e) { throw new PgpKeyNotFoundException(e); } } private Cursor getSubkeys() throws PgpKeyNotFoundException { Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId()); - return mProviderHelper.getContentResolver().query(keysUri, null, null, null, null); + return mDatabaseInteractor.getContentResolver().query(keysUri, null, null, null, null); } public SecretKeyType getSecretKeyType(long keyId) throws NotFoundException { - Object data = mProviderHelper.getGenericData(Keys.buildKeysUri(mUri), + Object data = mDatabaseInteractor.getGenericData(Keys.buildKeysUri(mUri), KeyRings.HAS_SECRET, - ProviderHelper.FIELD_TYPE_INTEGER, + DatabaseInteractor.FIELD_TYPE_INTEGER, KeyRings.KEY_ID + " = " + Long.toString(keyId)); return SecretKeyType.fromNum(((Long) data).intValue()); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java similarity index 99% rename from OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java rename to OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java index 9b42c0cab..1d1b93d93 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/DatabaseInteractor.java @@ -91,21 +91,21 @@ import java.util.concurrent.TimeUnit; * the lifetime of the executing ProviderHelper object unless the resetLog() * method is called to start a new one specifically. */ -public class ProviderHelper { +public class DatabaseInteractor { private final Context mContext; private final ContentResolver mContentResolver; private OperationLog mLog; private int mIndent; - public ProviderHelper(Context context) { + public DatabaseInteractor(Context context) { this(context, new OperationLog(), 0); } - public ProviderHelper(Context context, OperationLog log) { + public DatabaseInteractor(Context context, OperationLog log) { this(context, log, 0); } - public ProviderHelper(Context context, OperationLog log, int indent) { + public DatabaseInteractor(Context context, OperationLog log, int indent) { mContext = context; mContentResolver = context.getContentResolver(); mLog = log; @@ -1335,7 +1335,7 @@ public class ProviderHelper { private ConsolidateResult consolidateDatabaseStep2( OperationLog log, int indent, Progressable progress, boolean recovery) { - synchronized (ProviderHelper.class) { + synchronized (DatabaseInteractor.class) { if (mConsolidateCritical) { log.add(LogType.MSG_CON_ERROR_CONCURRENT, indent); return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, log); @@ -1540,7 +1540,7 @@ public class ProviderHelper { public String getKeyRingAsArmoredString(Uri uri) throws NotFoundException, IOException, PgpGeneralException { byte[] data = (byte[]) getGenericData( - uri, KeyRingData.KEY_RING_DATA, ProviderHelper.FIELD_TYPE_BLOB); + uri, KeyRingData.KEY_RING_DATA, DatabaseInteractor.FIELD_TYPE_BLOB); return getKeyRingAsArmoredString(data); } 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 816f80600..167302440 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -66,7 +66,7 @@ import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAccounts; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.remote.OpenPgpServiceKeyIdExtractor.KeyIdResult; import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -88,7 +88,7 @@ public class OpenPgpService extends Service { Collections.unmodifiableList(Arrays.asList(3, 4, 5, 6, 7, 8, 9, 10, 11)); private ApiPermissionHelper mApiPermissionHelper; - private ProviderHelper mProviderHelper; + private DatabaseInteractor mDatabaseInteractor; private ApiDataAccessObject mApiDao; private OpenPgpServiceKeyIdExtractor mKeyIdExtractor; private ApiPendingIntentFactory mApiPendingIntentFactory; @@ -97,7 +97,7 @@ public class OpenPgpService extends Service { public void onCreate() { super.onCreate(); mApiPermissionHelper = new ApiPermissionHelper(this, new ApiDataAccessObject(this)); - mProviderHelper = new ProviderHelper(this); + mDatabaseInteractor = new DatabaseInteractor(this); mApiDao = new ApiDataAccessObject(this); mApiPendingIntentFactory = new ApiPendingIntentFactory(getBaseContext()); @@ -135,7 +135,7 @@ public class OpenPgpService extends Service { // get first usable subkey capable of signing try { - long signSubKeyId = mProviderHelper.getCachedPublicKeyRing( + long signSubKeyId = mDatabaseInteractor.getCachedPublicKeyRing( pgpData.getSignatureMasterKeyId()).getSecretSignId(); pgpData.setSignatureSubKeyId(signSubKeyId); } catch (PgpKeyNotFoundException e) { @@ -167,7 +167,7 @@ public class OpenPgpService extends Service { } // execute PGP operation! - PgpSignEncryptOperation pse = new PgpSignEncryptOperation(this, new ProviderHelper(this), null); + PgpSignEncryptOperation pse = new PgpSignEncryptOperation(this, new DatabaseInteractor(this), null); PgpSignEncryptResult pgpResult = pse.execute(pseInput, inputParcel, inputData, outputStream); if (pgpResult.isPending()) { @@ -254,7 +254,7 @@ public class OpenPgpService extends Service { // get first usable subkey capable of signing try { - long signSubKeyId = mProviderHelper.getCachedPublicKeyRing( + long signSubKeyId = mDatabaseInteractor.getCachedPublicKeyRing( pgpData.getSignatureMasterKeyId()).getSecretSignId(); pgpData.setSignatureSubKeyId(signSubKeyId); } catch (PgpKeyNotFoundException e) { @@ -294,7 +294,7 @@ public class OpenPgpService extends Service { new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE)); } - PgpSignEncryptOperation op = new PgpSignEncryptOperation(this, mProviderHelper, null); + PgpSignEncryptOperation op = new PgpSignEncryptOperation(this, mDatabaseInteractor, null); // execute PGP operation! PgpSignEncryptResult pgpResult = op.execute(pseInput, inputParcel, inputData, outputStream); @@ -356,7 +356,7 @@ public class OpenPgpService extends Service { byte[] detachedSignature = data.getByteArrayExtra(OpenPgpApi.EXTRA_DETACHED_SIGNATURE); String senderAddress = data.getStringExtra(OpenPgpApi.EXTRA_SENDER_ADDRESS); - PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(this, mProviderHelper, progressable); + PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(this, mDatabaseInteractor, progressable); long inputLength = data.getLongExtra(OpenPgpApi.EXTRA_DATA_LENGTH, InputData.UNKNOWN_FILESIZE); InputData inputData = new InputData(inputStream, inputLength); @@ -526,7 +526,7 @@ public class OpenPgpService extends Service { try { // try to find key, throws NotFoundException if not in db! CanonicalizedPublicKeyRing keyRing = - mProviderHelper.getCanonicalizedPublicKeyRing( + mDatabaseInteractor.getCanonicalizedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(masterKeyId)); Intent result = new Intent(); @@ -555,7 +555,7 @@ public class OpenPgpService extends Service { mApiPendingIntentFactory.createShowKeyPendingIntent(data, masterKeyId)); return result; - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { // If keys are not in db we return an additional PendingIntent // to retrieve the missing key Intent result = new Intent(); @@ -630,7 +630,7 @@ public class OpenPgpService extends Service { // the backup code is cached in CryptoInputParcelCacheService, now we can proceed BackupKeyringParcel input = new BackupKeyringParcel(masterKeyIds, backupSecret, true, enableAsciiArmorOutput, null); - BackupOperation op = new BackupOperation(this, mProviderHelper, null); + BackupOperation op = new BackupOperation(this, mDatabaseInteractor, null); ExportResult pgpResult = op.execute(input, inputParcel, outputStream); if (pgpResult.success()) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java index b4de0fe7d..467d51675 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/RequestKeyPermissionPresenter.java @@ -16,8 +16,8 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.remote.ApiPermissionHelper; import org.sufficientlysecure.keychain.remote.ApiPermissionHelper.WrongPackageCertificateException; import org.sufficientlysecure.keychain.util.Log; @@ -33,26 +33,26 @@ class RequestKeyPermissionPresenter { private String packageName; private long masterKeyId; - private ProviderHelper providerHelper; + private DatabaseInteractor databaseInteractor; static RequestKeyPermissionPresenter createRequestKeyPermissionPresenter(Context context) { PackageManager packageManager = context.getPackageManager(); ApiDataAccessObject apiDataAccessObject = new ApiDataAccessObject(context); ApiPermissionHelper apiPermissionHelper = new ApiPermissionHelper(context, apiDataAccessObject); - ProviderHelper providerHelper = new ProviderHelper(context); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(context); return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager, - providerHelper); + databaseInteractor); } private RequestKeyPermissionPresenter(Context context, ApiDataAccessObject apiDataAccessObject, - ApiPermissionHelper apiPermissionHelper, PackageManager packageManager, ProviderHelper providerHelper) { + ApiPermissionHelper apiPermissionHelper, PackageManager packageManager, DatabaseInteractor databaseInteractor) { this.context = context; this.apiDataAccessObject = apiDataAccessObject; this.apiPermissionHelper = apiPermissionHelper; this.packageManager = packageManager; - this.providerHelper = providerHelper; + this.databaseInteractor = databaseInteractor; } void setView(RequestKeyPermissionMvpView view) { @@ -101,7 +101,7 @@ class RequestKeyPermissionPresenter { CachedPublicKeyRing publicFallbackRing = null; for (long candidateSubKeyId : subKeyIds) { try { - CachedPublicKeyRing cachedPublicKeyRing = providerHelper.getCachedPublicKeyRing( + CachedPublicKeyRing cachedPublicKeyRing = databaseInteractor.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(candidateSubKeyId) ); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java index c287f6b38..c9b8f2103 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainService.java @@ -48,7 +48,7 @@ import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyOperation; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.SignEncryptParcel; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ServiceProgressHandler.MessageStatus; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.util.Log; @@ -112,35 +112,35 @@ public class KeychainService extends Service implements Progressable { // just for brevity KeychainService outerThis = KeychainService.this; if (inputParcel instanceof SignEncryptParcel) { - op = new SignEncryptOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new SignEncryptOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof PgpDecryptVerifyInputParcel) { - op = new PgpDecryptVerifyOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new PgpDecryptVerifyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof SaveKeyringParcel) { - op = new EditKeyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new EditKeyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof ChangeUnlockParcel) { - op = new ChangeUnlockOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new ChangeUnlockOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof RevokeKeyringParcel) { - op = new RevokeOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new RevokeOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof CertifyActionsParcel) { - op = new CertifyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new CertifyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof DeleteKeyringParcel) { - op = new DeleteOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new DeleteOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof PromoteKeyringParcel) { - op = new PromoteKeyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new PromoteKeyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof ImportKeyringParcel) { - op = new ImportOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new ImportOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof BackupKeyringParcel) { - op = new BackupOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new BackupOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof UploadKeyringParcel) { - op = new UploadOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled); + op = new UploadOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled); } else if (inputParcel instanceof ConsolidateInputParcel) { - op = new ConsolidateOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new ConsolidateOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof KeybaseVerificationParcel) { - op = new KeybaseVerificationOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new KeybaseVerificationOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof InputDataParcel) { - op = new InputDataOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new InputDataOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else if (inputParcel instanceof BenchmarkInputParcel) { - op = new BenchmarkOperation(outerThis, new ProviderHelper(outerThis), outerThis); + op = new BenchmarkOperation(outerThis, new DatabaseInteractor(outerThis), outerThis); } else { throw new AssertionError("Unrecognized input parcel in KeychainService!"); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java index e72df4d7c..30e4387ef 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeyserverSyncAdapterService.java @@ -36,7 +36,7 @@ import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.network.NetworkReceiver; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity; @@ -320,7 +320,7 @@ public class KeyserverSyncAdapterService extends Service { private ImportKeyResult directUpdate(Context context, ArrayList keyList, CryptoInputParcel cryptoInputParcel) { Log.d(Constants.TAG, "Starting normal update"); - ImportOperation importOp = new ImportOperation(context, new ProviderHelper(context), null); + ImportOperation importOp = new ImportOperation(context, new DatabaseInteractor(context), null); return importOp.execute( new ImportKeyringParcel(keyList, Preferences.getPreferences(context).getPreferredKeyserver()), @@ -380,7 +380,7 @@ public class KeyserverSyncAdapterService extends Service { new OperationResult.OperationLog()); } ImportKeyResult result = - new ImportOperation(context, new ProviderHelper(context), null, mCancelled) + new ImportOperation(context, new DatabaseInteractor(context), null, mCancelled) .execute( new ImportKeyringParcel( keyWrapper, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index f9ab58f5b..fb6f1e08b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Preferences; @@ -224,7 +224,7 @@ public class PassphraseCacheService extends Service { /** * Internal implementation to get cached passphrase. */ - private Passphrase getCachedPassphraseImpl(long masterKeyId, long subKeyId) throws ProviderHelper.NotFoundException { + private Passphrase getCachedPassphraseImpl(long masterKeyId, long subKeyId) throws DatabaseInteractor.NotFoundException { // on "none" key, just do nothing if (masterKeyId == Constants.key.none) { return null; @@ -245,16 +245,16 @@ public class PassphraseCacheService extends Service { + masterKeyId + ", subKeyId " + subKeyId); // get the type of key (from the database) - CachedPublicKeyRing keyRing = new ProviderHelper(this).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing keyRing = new DatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId); switch (keyType) { case PASSPHRASE_EMPTY: return new Passphrase(""); case UNAVAILABLE: - throw new ProviderHelper.NotFoundException("secret key for this subkey is not available"); + throw new DatabaseInteractor.NotFoundException("secret key for this subkey is not available"); case GNU_DUMMY: - throw new ProviderHelper.NotFoundException("secret key for stripped subkey is not available"); + throw new DatabaseInteractor.NotFoundException("secret key for stripped subkey is not available"); } // get cached passphrase @@ -398,7 +398,7 @@ public class PassphraseCacheService extends Service { bundle.putParcelable(EXTRA_PASSPHRASE, passphrase); msg.setData(bundle); } - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "PassphraseCacheService: Passphrase for unknown key was requested!"); msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java index 3c1be0e2b..ad65fde71 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyFingerprintFragment.java @@ -35,7 +35,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.experimental.SentenceConfirm; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.LoaderFragment; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; @@ -213,7 +213,7 @@ public class CertifyFingerprintFragment extends LoaderFragment implements private void certify(Uri dataUri) { long keyId = 0; try { - keyId = new ProviderHelper(getActivity()) + keyId = new DatabaseInteractor(getActivity()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { 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 ad39ff43d..b44969b7c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -20,37 +20,25 @@ package org.sufficientlysecure.keychain.ui; import android.app.Activity; import android.content.Intent; -import android.database.Cursor; -import android.database.MatrixCursor; import android.graphics.PorterDuff; -import android.net.Uri; import android.os.Bundle; -import android.os.Parcel; -import android.support.v4.app.LoaderManager; -import android.support.v4.content.CursorLoader; -import android.support.v4.content.Loader; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.ImageView; -import android.widget.ListView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.operations.results.CertifyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; -import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; -import org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter; import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.FormattingUtils; @@ -80,7 +68,7 @@ public class CertifyKeyFragment .getLongExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, Constants.key.none); if (certifyKeyId != Constants.key.none) { try { - CachedPublicKeyRing key = (new ProviderHelper(getActivity())) + CachedPublicKeyRing key = (new DatabaseInteractor(getActivity())) .getCachedPublicKeyRing(certifyKeyId); if (key.canCertify()) { mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java index 19cbb7660..84a39108d 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyActivity.java @@ -30,7 +30,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.securitytoken.KeyFormat; import org.sufficientlysecure.keychain.ui.base.BaseSecurityTokenActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -180,7 +180,7 @@ public class CreateKeyActivity extends BaseSecurityTokenActivity { if (containsKeys(mScannedFingerprints)) { try { long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mScannedFingerprints); - CachedPublicKeyRing ring = new ProviderHelper(this).getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing ring = new DatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId); ring.getMasterKeyId(); Intent intent = new Intent(this, ViewKeyActivity.class); 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 924a97df2..a3e8c3fe2 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CreateKeyFinalFragment.java @@ -41,14 +41,12 @@ import org.sufficientlysecure.keychain.operations.results.EditKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.UploadResult; import org.sufficientlysecure.keychain.pgp.KeyRing; -import org.sufficientlysecure.keychain.pgp.PgpSecurityConstants; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; -import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction; @@ -413,7 +411,7 @@ public class CreateKeyFinalFragment extends Fragment { CreateKeyActivity activity = (CreateKeyActivity) getActivity(); final SaveKeyringParcel changeKeyringParcel; - CachedPublicKeyRing key = (new ProviderHelper(activity)) + CachedPublicKeyRing key = (new DatabaseInteractor(activity)) .getCachedPublicKeyRing(saveKeyResult.mMasterKeyId); try { changeKeyringParcel = new SaveKeyringParcel(key.getMasterKeyId(), key.getFingerprint()); 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 4458fd2b0..2bc84687e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DecryptFragment.java @@ -47,7 +47,7 @@ import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -192,7 +192,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager. try { Intent viewKeyIntent = new Intent(getActivity(), ViewKeyActivity.class); - long masterKeyId = new ProviderHelper(getActivity()).getCachedPublicKeyRing( + long masterKeyId = new DatabaseInteractor(getActivity()).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId) ).getMasterKeyId(); viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java index 1827fd4e4..84d94586b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java @@ -35,16 +35,14 @@ import android.widget.AdapterView; import android.widget.Spinner; import android.widget.TextView; -import org.openintents.openpgp.util.OpenPgpUtils; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.keyimport.ParcelableHkpKeyserver; import org.sufficientlysecure.keychain.operations.results.DeleteResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.RevokeResult; -import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.DeleteKeyringParcel; import org.sufficientlysecure.keychain.service.RevokeKeyringParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -91,13 +89,13 @@ public class DeleteKeyDialogActivity extends FragmentActivity { if (mMasterKeyIds.length == 1 && mHasSecret) { // if mMasterKeyIds.length == 0 we let the DeleteOperation respond try { - HashMap data = new ProviderHelper(this).getUnifiedData( + HashMap data = new DatabaseInteractor(this).getUnifiedData( mMasterKeyIds[0], new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.IS_REVOKED }, new int[]{ - ProviderHelper.FIELD_TYPE_STRING, - ProviderHelper.FIELD_TYPE_INTEGER + DatabaseInteractor.FIELD_TYPE_STRING, + DatabaseInteractor.FIELD_TYPE_INTEGER } ); @@ -114,7 +112,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { } else { showRevokeDeleteDialog(name); } - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "Secret key to delete not found at DeleteKeyDialogActivity for " + mMasterKeyIds[0], e); @@ -271,13 +269,13 @@ public class DeleteKeyDialogActivity extends FragmentActivity { long masterKeyId = masterKeyIds[0]; try { - HashMap data = new ProviderHelper(activity).getUnifiedData( + HashMap data = new DatabaseInteractor(activity).getUnifiedData( masterKeyId, new String[]{ KeychainContract.KeyRings.NAME, KeychainContract.KeyRings.HAS_ANY_SECRET }, new int[]{ - ProviderHelper.FIELD_TYPE_STRING, - ProviderHelper.FIELD_TYPE_INTEGER + DatabaseInteractor.FIELD_TYPE_STRING, + DatabaseInteractor.FIELD_TYPE_INTEGER } ); String name; @@ -295,7 +293,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { } else { mMainMessage.setText(getString(R.string.public_key_deletetion_confirmation, name)); } - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { dismiss(); return null; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java index 248cd71b3..c34b2b994 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditIdentitiesFragment.java @@ -51,8 +51,8 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.UploadKeyringParcel; import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter; @@ -170,7 +170,7 @@ public class EditIdentitiesFragment extends Fragment try { Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri); CachedPublicKeyRing keyRing = - new ProviderHelper(getActivity()).getCachedPublicKeyRing(secretUri); + new DatabaseInteractor(getActivity()).getCachedPublicKeyRing(secretUri); long masterKeyId = keyRing.getMasterKeyId(); // check if this is a master secret key we can work with 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 6bf7cae15..c766472f4 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EditKeyFragment.java @@ -50,8 +50,8 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.SubkeyChange; @@ -203,7 +203,7 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment return; } - ProviderHelper providerHelper = new ProviderHelper(activity); - Cursor cursor = providerHelper.getContentResolver().query( + DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity); + Cursor cursor = databaseInteractor.getContentResolver().query( KeyRings.buildUnifiedKeyRingsUri(), new String[]{ KeyRings.FINGERPRINT }, null, null, null diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java index b7da02096..e0b4b1ba6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java @@ -31,7 +31,6 @@ import android.support.v4.app.FragmentActivity; import android.support.v7.app.AlertDialog; import android.text.Editable; import android.text.InputType; -import android.text.Layout; import android.text.TextWatcher; import android.text.method.PasswordTransformationMethod; import android.view.ContextThemeWrapper; @@ -59,8 +58,8 @@ 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; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -113,7 +112,7 @@ public class PassphraseDialogActivity extends FragmentActivity { // handle empty passphrases by directly returning an empty crypto input parcel try { CachedPublicKeyRing pubRing = - new ProviderHelper(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); + new DatabaseInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId()); // use empty passphrase for empty passphrase if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) { // also return passphrase back to activity @@ -232,7 +231,7 @@ public class PassphraseDialogActivity extends FragmentActivity { try { long subKeyId = mRequiredInput.getSubKeyId(); - ProviderHelper helper = new ProviderHelper(activity); + DatabaseInteractor helper = new DatabaseInteractor(activity); CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); // yes the inner try/catch block is necessary, otherwise the final variable @@ -267,7 +266,7 @@ public class PassphraseDialogActivity extends FragmentActivity { throw new AssertionError("Unhandled SecretKeyType (should not happen)"); } - } catch (PgpKeyNotFoundException | ProviderHelper.NotFoundException e) { + } catch (PgpKeyNotFoundException | DatabaseInteractor.NotFoundException e) { alert.setTitle(R.string.title_key_not_found); alert.setMessage(getString(R.string.key_not_found, mRequiredInput.getSubKeyId())); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @@ -458,7 +457,7 @@ public class PassphraseDialogActivity extends FragmentActivity { Long subKeyId = mRequiredInput.getSubKeyId(); CanonicalizedSecretKeyRing secretKeyRing = - new ProviderHelper(getActivity()).getCanonicalizedSecretKeyRing( + new DatabaseInteractor(getActivity()).getCanonicalizedSecretKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); CanonicalizedSecretKey secretKeyToUnlock = secretKeyRing.getSecretKey(subKeyId); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java index e54852f1b..2f99a0b68 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/QrCodeViewActivity.java @@ -29,7 +29,7 @@ import android.widget.ImageView; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.Notify; @@ -74,11 +74,11 @@ public class QrCodeViewActivity extends BaseActivity { } }); - ProviderHelper providerHelper = new ProviderHelper(this); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(this); try { - byte[] blob = (byte[]) providerHelper.getGenericData( + byte[] blob = (byte[]) databaseInteractor.getGenericData( KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri), - KeychainContract.KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); + KeychainContract.KeyRings.FINGERPRINT, DatabaseInteractor.FIELD_TYPE_BLOB); if (blob == null) { Log.e(Constants.TAG, "key not found!"); Notify.create(this, R.string.error_key_not_found, Style.ERROR).show(); @@ -102,7 +102,7 @@ public class QrCodeViewActivity extends BaseActivity { mQrCode.setImageBitmap(scaled); } }); - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); Notify.create(this, R.string.error_key_not_found, Style.ERROR).show(); ActivityCompat.finishAfterTransition(QrCodeViewActivity.this); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java index 410e511fa..4dec17128 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java @@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.operations.ImportOperation; import org.sufficientlysecure.keychain.operations.results.ImportKeyResult; import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; @@ -105,8 +105,8 @@ public class SafeSlingerActivity extends BaseActivity // retrieve public key blob and start SafeSlinger Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId); try { - byte[] keyBlob = (byte[]) new ProviderHelper(this).getGenericData( - uri, KeychainContract.KeyRingData.KEY_RING_DATA, ProviderHelper.FIELD_TYPE_BLOB); + byte[] keyBlob = (byte[]) new DatabaseInteractor(this).getGenericData( + uri, KeychainContract.KeyRingData.KEY_RING_DATA, DatabaseInteractor.FIELD_TYPE_BLOB); Intent slingerIntent = new Intent(this, ExchangeActivity.class); @@ -114,7 +114,7 @@ public class SafeSlingerActivity extends BaseActivity slingerIntent.putExtra(ExchangeConfig.extra.USER_DATA, keyBlob); slingerIntent.putExtra(ExchangeConfig.extra.HOST_NAME, Constants.SAFESLINGER_SERVER); startActivityForResult(slingerIntent, REQUEST_CODE_SAFE_SLINGER); - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "personal key not found", e); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java index c663a2f18..94415e154 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SecurityTokenOperationActivity.java @@ -36,7 +36,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.securitytoken.KeyType; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -193,12 +193,12 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { throw new IOException(getString(R.string.error_wrong_security_token)); } - ProviderHelper providerHelper = new ProviderHelper(this); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(this); CanonicalizedPublicKeyRing publicKeyRing; try { - publicKeyRing = providerHelper.getCanonicalizedPublicKeyRing( + publicKeyRing = databaseInteractor.getCanonicalizedPublicKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId())); - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { throw new IOException("Couldn't find subkey for key to token operation."); } @@ -232,13 +232,13 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity { mSecurityTokenHelper.setPin(new Passphrase("123456")); mSecurityTokenHelper.setAdminPin(new Passphrase("12345678")); - ProviderHelper providerHelper = new ProviderHelper(this); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(this); CanonicalizedSecretKeyRing secretKeyRing; try { - secretKeyRing = providerHelper.getCanonicalizedSecretKeyRing( + secretKeyRing = databaseInteractor.getCanonicalizedSecretKeyRing( KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mRequiredInput.getMasterKeyId()) ); - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { throw new IOException("Couldn't find subkey for key to token operation."); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java index 596b223fe..d60518efc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewCertActivity.java @@ -40,7 +40,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.util.Log; @@ -184,8 +184,8 @@ public class ViewCertActivity extends BaseActivity Intent viewIntent = new Intent(ViewCertActivity.this, ViewKeyActivity.class); try { - ProviderHelper providerHelper = new ProviderHelper(ViewCertActivity.this); - long signerMasterKeyId = providerHelper.getCachedPublicKeyRing( + DatabaseInteractor databaseInteractor = new DatabaseInteractor(ViewCertActivity.this); + long signerMasterKeyId = databaseInteractor.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId(); viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId)); startActivity(viewIntent); 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 2785b620d..593d6597c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -74,8 +74,8 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -125,7 +125,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements public static final String EXTRA_DISPLAY_RESULT = "display_result"; public static final String EXTRA_LINKED_TRANSITION = "linked_transition"; - ProviderHelper mProviderHelper; + DatabaseInteractor mDatabaseInteractor; protected Uri mDataUri; @@ -185,7 +185,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mProviderHelper = new ProviderHelper(this); + mDatabaseInteractor = new DatabaseInteractor(this); mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null); setTitle(null); @@ -318,7 +318,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements // or start new ones. getSupportLoaderManager().initLoader(LOADER_ID_UNIFIED, null, this); - mNfcHelper = new NfcHelper(this, mProviderHelper); + mNfcHelper = new NfcHelper(this, mDatabaseInteractor); mNfcHelper.initNfc(mDataUri); if (savedInstanceState == null && getIntent().hasExtra(EXTRA_DISPLAY_RESULT)) { @@ -399,8 +399,8 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements } case R.id.menu_key_view_refresh: { try { - updateFromKeyserver(mDataUri, mProviderHelper); - } catch (ProviderHelper.NotFoundException e) { + updateFromKeyserver(mDataUri, mDatabaseInteractor); + } catch (DatabaseInteractor.NotFoundException e) { Notify.create(this, R.string.error_key_not_found, Notify.Style.ERROR).show(); } return true; @@ -550,7 +550,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private boolean keyHasPassphrase() { try { SecretKeyType secretKeyType = - mProviderHelper.getCachedPublicKeyRing(mMasterKeyId).getSecretKeyType(mMasterKeyId); + mDatabaseInteractor.getCachedPublicKeyRing(mMasterKeyId).getSecretKeyType(mMasterKeyId); switch (secretKeyType) { // all of these make no sense to ask case PASSPHRASE_EMPTY: @@ -666,7 +666,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements try { // if the security token matches a subkey in any key - CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing( + CachedPublicKeyRing ring = mDatabaseInteractor.getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(tokenId)); byte[] candidateFp = ring.getFingerprint(); @@ -741,7 +741,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements return; } try { - long keyId = new ProviderHelper(this) + long keyId = new DatabaseInteractor(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); long[] encryptionKeyIds = new long[]{keyId}; @@ -765,7 +765,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = new ProviderHelper(this) + keyId = new DatabaseInteractor(this) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { @@ -1118,17 +1118,17 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements // CryptoOperationHelper.Callback functions - private void updateFromKeyserver(Uri dataUri, ProviderHelper providerHelper) - throws ProviderHelper.NotFoundException { + private void updateFromKeyserver(Uri dataUri, DatabaseInteractor databaseInteractor) + throws DatabaseInteractor.NotFoundException { mIsRefreshing = true; mRefreshItem.setEnabled(false); mRefreshItem.setActionView(mRefresh); mRefresh.startAnimation(mRotate); - byte[] blob = (byte[]) providerHelper.getGenericData( + byte[] blob = (byte[]) databaseInteractor.getGenericData( KeychainContract.KeyRings.buildUnifiedKeyRingUri(dataUri), - KeychainContract.Keys.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB); + KeychainContract.Keys.FINGERPRINT, DatabaseInteractor.FIELD_TYPE_BLOB); String fingerprint = KeyFormattingUtils.convertFingerprintToHex(blob); ParcelableKeyRing keyEntry = new ParcelableKeyRing(fingerprint, null, null, null); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java index faa8743da..b84c2498b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java @@ -41,13 +41,11 @@ import android.widget.Toast; import com.astuetz.PagerSlidingTabStrip; -import org.openintents.openpgp.util.OpenPgpUtils; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.operations.results.OperationResult; -import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; @@ -57,7 +55,7 @@ import org.sufficientlysecure.keychain.util.Log; public class ViewKeyAdvActivity extends BaseActivity implements LoaderCallbacks, OnPageChangeListener { - ProviderHelper mProviderHelper; + DatabaseInteractor mDatabaseInteractor; protected Uri mDataUri; @@ -90,7 +88,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements } }); - mProviderHelper = new ProviderHelper(this); + mDatabaseInteractor = new DatabaseInteractor(this); mViewPager = (ViewPager) findViewById(R.id.pager); mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 1ec82b907..046d96805 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -58,7 +58,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.ui.base.LoaderFragment; import org.sufficientlysecure.keychain.ui.util.FormattingUtils; @@ -93,8 +93,8 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements View root = super.onCreateView(inflater, superContainer, savedInstanceState); View view = inflater.inflate(R.layout.view_key_adv_share_fragment, getContainer()); - ProviderHelper providerHelper = new ProviderHelper(ViewKeyAdvShareFragment.this.getActivity()); - mNfcHelper = new NfcHelper(getActivity(), providerHelper); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(ViewKeyAdvShareFragment.this.getActivity()); + mNfcHelper = new NfcHelper(getActivity(), databaseInteractor); mFingerprintView = (TextView) view.findViewById(R.id.view_key_fingerprint); mQrCode = (ImageView) view.findViewById(R.id.view_key_qr_code); @@ -200,7 +200,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void startSafeSlinger(Uri dataUri) { long keyId = 0; try { - keyId = new ProviderHelper(getActivity()) + keyId = new DatabaseInteractor(getActivity()) .getCachedPublicKeyRing(dataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { @@ -216,10 +216,10 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements if (activity == null || mFingerprint == null) { return; } - ProviderHelper providerHelper = new ProviderHelper(activity); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(activity); try { - String content = providerHelper.getKeyRingAsArmoredString( + String content = databaseInteractor.getKeyRingAsArmoredString( KeychainContract.KeyRingData.buildPublicKeyRingUri(mDataUri)); if (toClipboard) { @@ -273,7 +273,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements } catch (PgpGeneralException | IOException e) { Log.e(Constants.TAG, "error processing key!", e); Notify.create(activity, R.string.error_key_processing, Notify.Style.ERROR).show(); - } catch (ProviderHelper.NotFoundException e) { + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); Notify.create(activity, R.string.error_key_not_found, Notify.Style.ERROR).show(); } @@ -457,7 +457,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements private void uploadToKeyserver() { long keyId; try { - keyId = new ProviderHelper(getActivity()) + keyId = new DatabaseInteractor(getActivity()) .getCachedPublicKeyRing(mDataUri) .extractOrGetMasterKeyId(); } catch (PgpKeyNotFoundException e) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 7b22d48ae..13c981746 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.ViewKeyActivity; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; @@ -65,7 +65,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter mData; private KeyState[] mKeyStates; - private ProviderHelper mProviderHelper; + private DatabaseInteractor mDatabaseInteractor; public ImportKeysAdapter(FragmentActivity activity, ImportKeysListener listener, boolean nonInteractive) { @@ -74,7 +74,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter data) { @@ -89,13 +89,13 @@ public class ImportKeysAdapter extends RecyclerView.Adapter 0; - } catch (ProviderHelper.NotFoundException | PgpKeyNotFoundException ignored) { + } catch (DatabaseInteractor.NotFoundException | PgpKeyNotFoundException ignored) { } mKeyStates[i] = keyState; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java index 17fe8f395..f8db70a95 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseSecurityTokenActivity.java @@ -38,7 +38,7 @@ import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; @@ -105,7 +105,7 @@ public abstract class BaseSecurityTokenActivity extends BaseActivity final long subKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(mSecurityTokenFingerprints); try { - CachedPublicKeyRing ring = new ProviderHelper(this).getCachedPublicKeyRing( + CachedPublicKeyRing ring = new DatabaseInteractor(this).getCachedPublicKeyRing( KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)); long masterKeyId = ring.getMasterKeyId(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java index 39e781c6d..b9ea3a7f7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/linked/LinkedIdWizard.java @@ -36,7 +36,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.util.Log; @@ -58,7 +58,7 @@ public class LinkedIdWizard extends BaseActivity { try { Uri uri = getIntent().getData(); uri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(uri); - CachedPublicKeyRing ring = new ProviderHelper(this).getCachedPublicKeyRing(uri); + CachedPublicKeyRing ring = new DatabaseInteractor(this).getCachedPublicKeyRing(uri); if (!ring.hasAnySecret()) { Log.e(Constants.TAG, "Linked Identities can only be added to secret keys!"); finish(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java index 7c2d1aa3f..3aef420bd 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/NfcHelper.java @@ -36,9 +36,8 @@ import android.provider.Settings; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.provider.KeychainContract; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.ui.util.Notify; -import org.sufficientlysecure.keychain.util.Log; import java.lang.ref.WeakReference; @@ -49,7 +48,7 @@ import java.lang.ref.WeakReference; public class NfcHelper { private Activity mActivity; - private ProviderHelper mProviderHelper; + private DatabaseInteractor mDatabaseInteractor; /** * NFC: This handler receives a message from onNdefPushComplete @@ -65,9 +64,9 @@ public class NfcHelper { /** * Initializes the NfcHelper. */ - public NfcHelper(final Activity activity, final ProviderHelper providerHelper) { + public NfcHelper(final Activity activity, final DatabaseInteractor databaseInteractor) { mActivity = activity; - mProviderHelper = providerHelper; + mDatabaseInteractor = databaseInteractor; mNfcHandler = new NfcHandler(mActivity); } @@ -129,11 +128,11 @@ public class NfcHelper { try { Uri blobUri = KeychainContract.KeyRingData.buildPublicKeyRingUri(dataUri); - mNfcKeyringBytes = (byte[]) mProviderHelper.getGenericData( + mNfcKeyringBytes = (byte[]) mDatabaseInteractor.getGenericData( blobUri, KeychainContract.KeyRingData.KEY_RING_DATA, - ProviderHelper.FIELD_TYPE_BLOB); - } catch (ProviderHelper.NotFoundException e) { + DatabaseInteractor.FIELD_TYPE_BLOB); + } catch (DatabaseInteractor.NotFoundException e) { Log.e(Constants.TAG, "key not found!", e); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java index 16345333d..31bd6571c 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BackupOperationTest.java @@ -44,7 +44,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow; import org.sufficientlysecure.keychain.pgp.WrappedSignature; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.BackupKeyringParcel; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; @@ -135,13 +135,13 @@ public class BackupOperationTest { @Before public void setUp() { - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; - providerHelper.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); - providerHelper.saveSecretKeyRing(mStaticRing2, new ProgressScaler()); + databaseInteractor.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); + databaseInteractor.saveSecretKeyRing(mStaticRing2, new ProgressScaler()); // ok NOW log verbosely! ShadowLog.stream = System.out; @@ -150,7 +150,7 @@ public class BackupOperationTest { @Test public void testExportAllLocalStripped() throws Exception { BackupOperation op = new BackupOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); // make sure there is a local cert (so the later checks that there are none are meaningful) assertTrue("second keyring has local certification", checkForLocal(mStaticRing2)); @@ -249,7 +249,7 @@ public class BackupOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); BackupOperation op = new BackupOperation(spyApplication, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); BackupKeyringParcel parcel = new BackupKeyringParcel( new long[] { mStaticRing1.getMasterKeyId() }, false, false, true, fakeOutputUri); @@ -306,7 +306,7 @@ public class BackupOperationTest { { // export encrypted BackupOperation op = new BackupOperation(spyApplication, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); BackupKeyringParcel parcel = new BackupKeyringParcel( new long[] { mStaticRing1.getMasterKeyId() }, false, true, true, fakeOutputUri); @@ -324,7 +324,7 @@ public class BackupOperationTest { { PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(outStream.toByteArray()); input.setAllowSymmetricDecryption(true); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java index d5c55cf07..5dec61169 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/BenchmarkOperationTest.java @@ -25,7 +25,7 @@ import org.junit.runner.RunWith; import org.robolectric.RuntimeEnvironment; import org.robolectric.shadows.ShadowLog; import org.sufficientlysecure.keychain.KeychainTestRunner; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.BenchmarkInputParcel; import java.io.PrintStream; @@ -47,7 +47,7 @@ public class BenchmarkOperationTest { @Test public void testBenchmark() throws Exception { BenchmarkOperation op = new BenchmarkOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); op.execute(new BenchmarkInputParcel(), null); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java index 8d6c94bba..398831920 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/CertifyOperationTest.java @@ -35,7 +35,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.WrappedUserAttribute; import org.sufficientlysecure.keychain.provider.KeychainContract.Certs; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; @@ -117,13 +117,13 @@ public class CertifyOperationTest { @Before public void setUp() throws Exception { - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; - providerHelper.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); - providerHelper.savePublicKeyRing(mStaticRing2.extractPublicKeyRing(), new ProgressScaler(), null); + databaseInteractor.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); + databaseInteractor.savePublicKeyRing(mStaticRing2.extractPublicKeyRing(), new ProgressScaler(), null); // ok NOW log verbosely! ShadowLog.stream = System.out; @@ -132,7 +132,7 @@ public class CertifyOperationTest { @Test public void testSelfCertifyFlag() throws Exception { - CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing1.getMasterKeyId()); Assert.assertEquals("secret key must be marked self-certified in database", // TODO this should be more correctly be VERIFIED_SELF at some point! @@ -143,10 +143,10 @@ public class CertifyOperationTest { @Test public void testCertifyId() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); { - CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("public key must not be marked verified prior to certification", Certs.UNVERIFIED, ring.getVerified()); @@ -160,7 +160,7 @@ public class CertifyOperationTest { Assert.assertTrue("certification must succeed", result.success()); { - CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("new key must be verified now", Certs.VERIFIED_SECRET, ring.getVerified()); @@ -171,10 +171,10 @@ public class CertifyOperationTest { @Test public void testCertifyAttribute() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); { - CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("public key must not be marked verified prior to certification", Certs.UNVERIFIED, ring.getVerified()); @@ -188,7 +188,7 @@ public class CertifyOperationTest { Assert.assertTrue("certification must succeed", result.success()); { - CanonicalizedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedPublicKeyRing(mStaticRing2.getMasterKeyId()); Assert.assertEquals("new key must be verified now", Certs.VERIFIED_SECRET, ring.getVerified()); @@ -200,7 +200,7 @@ public class CertifyOperationTest { @Test public void testCertifySelf() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); actions.add(new CertifyAction(mStaticRing1.getMasterKeyId(), @@ -217,7 +217,7 @@ public class CertifyOperationTest { public void testCertifyNonexistent() throws Exception { CertifyOperation op = new CertifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); { CertifyActionsParcel actions = new CertifyActionsParcel(mStaticRing1.getMasterKeyId()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java index b8c3e2860..5cb914448 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/operations/PromoteKeyOperationTest.java @@ -38,7 +38,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.UncachedPublicKey; import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.PromoteKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; @@ -90,12 +90,12 @@ public class PromoteKeyOperationTest { @Before public void setUp() throws Exception { - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; - providerHelper.savePublicKeyRing(mStaticRing.extractPublicKeyRing(), new ProgressScaler(), null); + databaseInteractor.savePublicKeyRing(mStaticRing.extractPublicKeyRing(), new ProgressScaler(), null); // ok NOW log verbosely! ShadowLog.stream = System.out; @@ -104,14 +104,14 @@ public class PromoteKeyOperationTest { @Test public void testPromote() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); PromoteKeyResult result = op.execute(new PromoteKeyringParcel(mStaticRing.getMasterKeyId(), null, null), null); Assert.assertTrue("promotion must succeed", result.success()); { - CachedPublicKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CachedPublicKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCachedPublicKeyRing(mStaticRing.getMasterKeyId()); Assert.assertTrue("key must have a secret now", ring.hasAnySecret()); @@ -128,7 +128,7 @@ public class PromoteKeyOperationTest { @Test public void testPromoteDivert() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); byte[] aid = Hex.decode("D2760001240102000000012345670000"); @@ -137,7 +137,7 @@ public class PromoteKeyOperationTest { Assert.assertTrue("promotion must succeed", result.success()); { - CanonicalizedSecretKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedSecretKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { @@ -153,7 +153,7 @@ public class PromoteKeyOperationTest { @Test public void testPromoteDivertSpecific() throws Exception { PromoteKeyOperation op = new PromoteKeyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null, null); + new DatabaseInteractor(RuntimeEnvironment.application), null, null); byte[] aid = Hex.decode("D2760001240102000000012345670000"); @@ -167,7 +167,7 @@ public class PromoteKeyOperationTest { Assert.assertTrue("promotion must succeed", result.success()); { - CanonicalizedSecretKeyRing ring = new ProviderHelper(RuntimeEnvironment.application) + CanonicalizedSecretKeyRing ring = new DatabaseInteractor(RuntimeEnvironment.application) .getCanonicalizedSecretKeyRing(mStaticRing.getMasterKeyId()); for (CanonicalizedSecretKey key : ring.secretKeyIterator()) { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java index 2d518eaa6..19033606d 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/InputDataOperationTest.java @@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.KeychainTestRunner; import org.sufficientlysecure.keychain.operations.InputDataOperation; import org.sufficientlysecure.keychain.operations.results.InputDataResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.provider.TemporaryFileProvider; import org.sufficientlysecure.keychain.service.InputDataParcel; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -126,7 +126,7 @@ public class InputDataOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); InputDataOperation op = new InputDataOperation(spyApplication, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputDataParcel input = new InputDataParcel(fakeInputUri, null); @@ -306,7 +306,7 @@ public class InputDataOperationTest { when(spyApplication.getContentResolver()).thenReturn(mockResolver); InputDataOperation op = new InputDataOperation(spyApplication, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputDataParcel input = new InputDataParcel(FAKE_CONTENT_INPUT_URI_1, null); return op.execute(input, new CryptoInputParcel()); diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java index 575cc33cc..4cab67f5d 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/pgp/PgpEncryptDecryptTest.java @@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp import org.sufficientlysecure.keychain.operations.results.PgpEditKeyResult; import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.service.ChangeUnlockParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; @@ -149,13 +149,13 @@ public class PgpEncryptDecryptTest { @Before public void setUp() { - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); // don't log verbosely here, we're not here to test imports ShadowLog.stream = oldShadowStream; - providerHelper.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); - providerHelper.saveSecretKeyRing(mStaticRing2, new ProgressScaler()); + databaseInteractor.saveSecretKeyRing(mStaticRing1, new ProgressScaler()); + databaseInteractor.saveSecretKeyRing(mStaticRing2, new ProgressScaler()); // ok NOW log verbosely! ShadowLog.stream = System.out; @@ -172,7 +172,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -197,7 +197,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute( @@ -227,7 +227,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute(input, @@ -249,7 +249,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(true); DecryptVerifyResult result = op.execute(input, @@ -270,7 +270,7 @@ public class PgpEncryptDecryptTest { InputData data = new InputData(in, in.available()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(); input.setAllowSymmetricDecryption(false); DecryptVerifyResult result = op.execute(input, @@ -297,7 +297,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -353,7 +353,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -415,7 +415,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -472,7 +472,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -575,7 +575,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -626,11 +626,11 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); - providerHelper.saveSecretKeyRing(modified, new ProgressScaler()); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); @@ -648,11 +648,11 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); - providerHelper.saveSecretKeyRing(modified, new ProgressScaler()); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); PgpDecryptVerifyOperation op = new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(ciphertext); DecryptVerifyResult result = op.execute(input, new CryptoInputParcel(mKeyPhrase1)); @@ -675,8 +675,8 @@ public class PgpEncryptDecryptTest { new ArrayList(), new ArrayList(), new CryptoInputParcel(new Date(), mKeyPhrase1)); - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); - providerHelper.saveSecretKeyRing(modified, new ProgressScaler()); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); + databaseInteractor.saveSecretKeyRing(modified, new ProgressScaler()); } { // encrypt to this keyring, make sure it's not encrypted to the revoked subkey @@ -685,7 +685,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -730,7 +730,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -824,7 +824,7 @@ public class PgpEncryptDecryptTest { { // decryption with passphrase cached should succeed for the other key if first is gone // delete first key from database - new ProviderHelper(RuntimeEnvironment.application).getContentResolver().delete( + new DatabaseInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null ); @@ -859,7 +859,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -907,7 +907,7 @@ public class PgpEncryptDecryptTest { { // decryption with passphrase cached should succeed for the other key if first is gone // delete first key from database - new ProviderHelper(RuntimeEnvironment.application).getContentResolver().delete( + new DatabaseInteractor(RuntimeEnvironment.application).getContentResolver().delete( KeyRingData.buildPublicKeyRingUri(mStaticRing1.getMasterKeyId()), null, null ); @@ -946,7 +946,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaindata); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -1018,7 +1018,7 @@ public class PgpEncryptDecryptTest { ByteArrayInputStream in = new ByteArrayInputStream(plaintext.getBytes()); PgpSignEncryptOperation op = new PgpSignEncryptOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null); + new DatabaseInteractor(RuntimeEnvironment.application), null); InputData data = new InputData(in, in.available()); @@ -1069,7 +1069,7 @@ public class PgpEncryptDecryptTest { final Passphrase passphrase, final Long checkMasterKeyId, final Long checkSubKeyId) { return new PgpDecryptVerifyOperation(RuntimeEnvironment.application, - new ProviderHelper(RuntimeEnvironment.application), null) { + new DatabaseInteractor(RuntimeEnvironment.application), null) { @Override public Passphrase getCachedPassphrase(long masterKeyId, long subKeyId) throws NoSecretKeyException { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperKeyringTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorKeyringTest.java similarity index 98% rename from OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperKeyringTest.java rename to OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorKeyringTest.java index 62358d848..608ecd950 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperKeyringTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorKeyringTest.java @@ -30,7 +30,7 @@ import java.util.Collection; import java.util.Collections; @RunWith(KeychainTestRunner.class) -public class ProviderHelperKeyringTest { +public class DatabaseInteractorKeyringTest { @Test public void testSavePublicKeyring() throws Exception { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java similarity index 83% rename from OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java rename to OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java index f22464185..a4f31581e 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/ProviderHelperSaveTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/DatabaseInteractorSaveTest.java @@ -41,9 +41,9 @@ import java.util.Arrays; import java.util.Iterator; @RunWith(KeychainTestRunner.class) -public class ProviderHelperSaveTest { +public class DatabaseInteractorSaveTest { - ProviderHelper mProviderHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor mDatabaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); @BeforeClass public static void setUpOnce() throws Exception { @@ -61,17 +61,17 @@ public class ProviderHelperSaveTest { SaveKeyringResult result; // insert both keys, second should fail - result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(first); + result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); Assert.assertTrue("first keyring import should succeed", result.success()); - result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(second); + result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); Assert.assertFalse("second keyring import should fail", result.success()); new KeychainDatabase(RuntimeEnvironment.application).clearDatabase(); // and the other way around - result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(second); + result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(second); Assert.assertTrue("first keyring import should succeed", result.success()); - result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(first); + result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(first); Assert.assertFalse("second keyring import should fail", result.success()); } @@ -90,13 +90,13 @@ public class ProviderHelperSaveTest { SaveKeyringResult result; // insert secret, this should fail because of missing self-cert - result = new ProviderHelper(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); + result = new DatabaseInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); Assert.assertFalse("secret keyring import before pubring import should fail", result.success()); // insert pubkey, then seckey - both should succeed - result = new ProviderHelper(RuntimeEnvironment.application).savePublicKeyRing(pubkey); + result = new DatabaseInteractor(RuntimeEnvironment.application).savePublicKeyRing(pubkey); Assert.assertTrue("public keyring import should succeed", result.success()); - result = new ProviderHelper(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); + result = new DatabaseInteractor(RuntimeEnvironment.application).saveSecretKeyRing(seckey, new ProgressScaler()); Assert.assertTrue("secret keyring import after pubring import should succeed", result.success()); } @@ -108,10 +108,10 @@ public class ProviderHelperSaveTest { Assert.assertEquals("key flags should be zero", 0, (long) pub.canonicalize(new OperationLog(), 0).getPublicKey().getKeyUsage()); - mProviderHelper.savePublicKeyRing(pub); + mDatabaseInteractor.savePublicKeyRing(pub); - CachedPublicKeyRing cachedRing = mProviderHelper.getCachedPublicKeyRing(keyId); - CanonicalizedPublicKeyRing pubRing = mProviderHelper.getCanonicalizedPublicKeyRing(keyId); + CachedPublicKeyRing cachedRing = mDatabaseInteractor.getCachedPublicKeyRing(keyId); + CanonicalizedPublicKeyRing pubRing = mDatabaseInteractor.getCanonicalizedPublicKeyRing(keyId); Assert.assertEquals("master key should be encryption key", keyId, pubRing.getEncryptId()); Assert.assertEquals("master key should be encryption key (cached)", keyId, cachedRing.getEncryptId()); @@ -131,13 +131,13 @@ public class ProviderHelperSaveTest { SaveKeyringResult result; - result = mProviderHelper.saveSecretKeyRing(sec, new ProgressScaler()); + result = mDatabaseInteractor.saveSecretKeyRing(sec, new ProgressScaler()); Assert.assertTrue("import of secret keyring should succeed", result.success()); // make sure both the CanonicalizedSecretKeyRing as well as the CachedPublicKeyRing correctly // indicate the secret key type - CachedPublicKeyRing cachedRing = mProviderHelper.getCachedPublicKeyRing(keyId); - CanonicalizedSecretKeyRing secRing = mProviderHelper.getCanonicalizedSecretKeyRing(keyId); + CachedPublicKeyRing cachedRing = mDatabaseInteractor.getCachedPublicKeyRing(keyId); + CanonicalizedSecretKeyRing secRing = mDatabaseInteractor.getCanonicalizedSecretKeyRing(keyId); Iterator it = secRing.secretKeyIterator().iterator(); @@ -195,10 +195,10 @@ public class ProviderHelperSaveTest { SaveKeyringResult result; - result = mProviderHelper.savePublicKeyRing(key, new ProgressScaler(), null); + result = mDatabaseInteractor.savePublicKeyRing(key, new ProgressScaler(), null); Assert.assertTrue("import of keyring should succeed", result.success()); - CanonicalizedPublicKeyRing ring = mProviderHelper.getCanonicalizedPublicKeyRing(keyId); + CanonicalizedPublicKeyRing ring = mDatabaseInteractor.getCanonicalizedPublicKeyRing(keyId); boolean found = false; byte[] badUserId = Hex.decode("436c61757320467261656e6b656c203c436c6175732e4672e46e6b656c4068616c696661782e727774682d61616368656e2e64653e"); for (byte[] rawUserId : new IterableIterator( @@ -222,29 +222,29 @@ public class ProviderHelperSaveTest { SaveKeyringResult result; - result = mProviderHelper.saveSecretKeyRing(key, new ProgressScaler()); + result = mDatabaseInteractor.saveSecretKeyRing(key, new ProgressScaler()); Assert.assertTrue("import of keyring should succeed", result.success()); long signId; { - CanonicalizedSecretKeyRing ring = mProviderHelper.getCanonicalizedSecretKeyRing(masterKeyId); + CanonicalizedSecretKeyRing ring = mDatabaseInteractor.getCanonicalizedSecretKeyRing(masterKeyId); Assert.assertTrue("master key should have sign flag", ring.getPublicKey().canSign()); Assert.assertTrue("master key should have encrypt flag", ring.getPublicKey().canEncrypt()); - signId = mProviderHelper.getCachedPublicKeyRing(masterKeyId).getSecretSignId(); + signId = mDatabaseInteractor.getCachedPublicKeyRing(masterKeyId).getSecretSignId(); Assert.assertNotEquals("encrypt id should not be 0", 0, signId); Assert.assertNotEquals("encrypt key should be different from master key", masterKeyId, signId); } { - CachedPublicKeyRing ring = mProviderHelper.getCachedPublicKeyRing(masterKeyId); + CachedPublicKeyRing ring = mDatabaseInteractor.getCachedPublicKeyRing(masterKeyId); Assert.assertEquals("signing key should be same id cached as uncached", signId, ring.getSecretSignId()); } } UncachedKeyRing readRingFromResource(String name) throws Exception { - return UncachedKeyRing.fromStream(ProviderHelperSaveTest.class.getResourceAsStream(name)).next(); + return UncachedKeyRing.fromStream(DatabaseInteractorSaveTest.class.getResourceAsStream(name)).next(); } } \ No newline at end of file diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java index f0bd955e1..a8a03d390 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/provider/InteropTest.java @@ -243,7 +243,7 @@ public class InteropTest { final Uri verifyUri = verify != null ? KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(verify.getMasterKeyId()) : null; - ProviderHelper helper = new ProviderHelper(RuntimeEnvironment.application) { + DatabaseInteractor helper = new DatabaseInteractor(RuntimeEnvironment.application) { @Override public CachedPublicKeyRing getCachedPublicKeyRing(Uri queryUri) throws PgpKeyNotFoundException { diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java index 7628c22c1..d72102005 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/remote/KeychainExternalProviderTest.java @@ -21,8 +21,8 @@ import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.provider.ApiDataAccessObject; import org.sufficientlysecure.keychain.provider.KeychainExternalContract.EmailStatus; -import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.provider.ProviderHelperSaveTest; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; +import org.sufficientlysecure.keychain.provider.DatabaseInteractorSaveTest; import org.sufficientlysecure.keychain.service.CertifyActionsParcel; import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; @@ -45,7 +45,7 @@ public class KeychainExternalProviderTest { static final long KEY_ID_PUBLIC = 0x9A282CE2AB44A382L; - ProviderHelper providerHelper = new ProviderHelper(RuntimeEnvironment.application); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(RuntimeEnvironment.application); ContentResolver contentResolver = RuntimeEnvironment.application.getContentResolver(); ApiPermissionHelper apiPermissionHelper; ApiDataAccessObject apiDao; @@ -187,7 +187,7 @@ public class KeychainExternalProviderTest { CertifyActionsParcel certifyActionsParcel = new CertifyActionsParcel(secretMasterKeyId); certifyActionsParcel.add(new CertifyAction(publicMasterKeyId, Collections.singletonList(userId), null)); CertifyOperation op = new CertifyOperation( - RuntimeEnvironment.application, providerHelper, new ProgressScaler(), null); + RuntimeEnvironment.application, databaseInteractor, new ProgressScaler(), null); CertifyResult certifyResult = op.execute(certifyActionsParcel, new CryptoInputParcel()); assertTrue(certifyResult.success()); @@ -195,17 +195,17 @@ public class KeychainExternalProviderTest { private void insertPublicKeyringFrom(String filename) throws Exception { UncachedKeyRing ring = readRingFromResource(filename); - SaveKeyringResult saveKeyringResult = providerHelper.savePublicKeyRing(ring); + SaveKeyringResult saveKeyringResult = databaseInteractor.savePublicKeyRing(ring); assertTrue(saveKeyringResult.success()); } private void insertSecretKeyringFrom(String filename) throws Exception { UncachedKeyRing ring = readRingFromResource(filename); - SaveKeyringResult saveKeyringResult = providerHelper.saveSecretKeyRing(ring, new ProgressScaler()); + SaveKeyringResult saveKeyringResult = databaseInteractor.saveSecretKeyRing(ring, new ProgressScaler()); assertTrue(saveKeyringResult.success()); } UncachedKeyRing readRingFromResource(String name) throws Exception { - return UncachedKeyRing.fromStream(ProviderHelperSaveTest.class.getResourceAsStream(name)).next(); + return UncachedKeyRing.fromStream(DatabaseInteractorSaveTest.class.getResourceAsStream(name)).next(); } } \ No newline at end of file diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/ProviderHelperStub.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java similarity index 86% rename from OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/ProviderHelperStub.java rename to OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java index 0573f07fb..f2ea24281 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/ProviderHelperStub.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/DatabaseInteractorStub.java @@ -21,10 +21,10 @@ import android.content.Context; import android.net.Uri; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; -class ProviderHelperStub extends ProviderHelper { - public ProviderHelperStub(Context context) { +class DatabaseInteractorStub extends DatabaseInteractor { + public DatabaseInteractorStub(Context context) { super(context); } diff --git a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java index d6e8112ca..e2756747f 100644 --- a/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java +++ b/OpenKeychain/src/test/java/org/sufficientlysecure/keychain/support/KeyringTestingHelper.java @@ -23,7 +23,7 @@ import android.content.Context; import org.bouncycastle.util.Arrays; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; -import org.sufficientlysecure.keychain.provider.ProviderHelper; +import org.sufficientlysecure.keychain.provider.DatabaseInteractor; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.util.ProgressScaler; @@ -50,24 +50,24 @@ public class KeyringTestingHelper { public boolean addKeyring(Collection blobFiles) throws Exception { - ProviderHelper providerHelper = new ProviderHelper(context); + DatabaseInteractor databaseInteractor = new DatabaseInteractor(context); byte[] data = TestDataUtil.readAllFully(blobFiles); UncachedKeyRing ring = UncachedKeyRing.decodeFromData(data); long masterKeyId = ring.getMasterKeyId(); // Should throw an exception; key is not yet saved - retrieveKeyAndExpectNotFound(providerHelper, masterKeyId); + retrieveKeyAndExpectNotFound(databaseInteractor, masterKeyId); - SaveKeyringResult saveKeyringResult = providerHelper.savePublicKeyRing(ring, new ProgressScaler(), null); + SaveKeyringResult saveKeyringResult = databaseInteractor.savePublicKeyRing(ring, new ProgressScaler(), null); boolean saveSuccess = saveKeyringResult.success(); // Now re-retrieve the saved key. Should not throw an exception. - providerHelper.getCanonicalizedPublicKeyRing(masterKeyId); + databaseInteractor.getCanonicalizedPublicKeyRing(masterKeyId); // A different ID should still fail - retrieveKeyAndExpectNotFound(providerHelper, masterKeyId - 1); + retrieveKeyAndExpectNotFound(databaseInteractor, masterKeyId - 1); return saveSuccess; } @@ -345,11 +345,11 @@ public class KeyringTestingHelper { return getNth(ring.getPublicKeys(), position).getKeyId(); } - private void retrieveKeyAndExpectNotFound(ProviderHelper providerHelper, long masterKeyId) { + private void retrieveKeyAndExpectNotFound(DatabaseInteractor databaseInteractor, long masterKeyId) { try { - providerHelper.getCanonicalizedPublicKeyRing(masterKeyId); + databaseInteractor.getCanonicalizedPublicKeyRing(masterKeyId); throw new AssertionError("Was expecting the previous call to fail!"); - } catch (ProviderHelper.NotFoundException expectedException) { + } catch (DatabaseInteractor.NotFoundException expectedException) { // good } }