extract DatabaseReadWriteInteractor

This commit is contained in:
Vincent Breitmoser
2017-02-20 16:28:30 +01:00
parent d577257bd5
commit aef6e6614e
62 changed files with 1658 additions and 1571 deletions

View File

@@ -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.DatabaseInteractor;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor;
import org.sufficientlysecure.keychain.service.ServiceProgressHandler.MessageStatus;
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
import org.sufficientlysecure.keychain.util.Log;
@@ -111,36 +111,37 @@ public class KeychainService extends Service implements Progressable {
// just for brevity
KeychainService outerThis = KeychainService.this;
DatabaseReadWriteInteractor databaseInteractor = new DatabaseReadWriteInteractor(outerThis);
if (inputParcel instanceof SignEncryptParcel) {
op = new SignEncryptOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled);
op = new SignEncryptOperation(outerThis, databaseInteractor, outerThis, mActionCanceled);
} else if (inputParcel instanceof PgpDecryptVerifyInputParcel) {
op = new PgpDecryptVerifyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis);
op = new PgpDecryptVerifyOperation(outerThis, databaseInteractor, outerThis);
} else if (inputParcel instanceof SaveKeyringParcel) {
op = new EditKeyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled);
op = new EditKeyOperation(outerThis, databaseInteractor, outerThis, mActionCanceled);
} else if (inputParcel instanceof ChangeUnlockParcel) {
op = new ChangeUnlockOperation(outerThis, new DatabaseInteractor(outerThis), outerThis);
op = new ChangeUnlockOperation(outerThis, databaseInteractor, outerThis);
} else if (inputParcel instanceof RevokeKeyringParcel) {
op = new RevokeOperation(outerThis, new DatabaseInteractor(outerThis), outerThis);
op = new RevokeOperation(outerThis, databaseInteractor, outerThis);
} else if (inputParcel instanceof CertifyActionsParcel) {
op = new CertifyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled);
op = new CertifyOperation(outerThis, databaseInteractor, outerThis, mActionCanceled);
} else if (inputParcel instanceof DeleteKeyringParcel) {
op = new DeleteOperation(outerThis, new DatabaseInteractor(outerThis), outerThis);
op = new DeleteOperation(outerThis, databaseInteractor, outerThis);
} else if (inputParcel instanceof PromoteKeyringParcel) {
op = new PromoteKeyOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled);
op = new PromoteKeyOperation(outerThis, databaseInteractor, outerThis, mActionCanceled);
} else if (inputParcel instanceof ImportKeyringParcel) {
op = new ImportOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled);
op = new ImportOperation(outerThis, databaseInteractor, outerThis, mActionCanceled);
} else if (inputParcel instanceof BackupKeyringParcel) {
op = new BackupOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled);
op = new BackupOperation(outerThis, databaseInteractor, outerThis, mActionCanceled);
} else if (inputParcel instanceof UploadKeyringParcel) {
op = new UploadOperation(outerThis, new DatabaseInteractor(outerThis), outerThis, mActionCanceled);
op = new UploadOperation(outerThis, databaseInteractor, outerThis, mActionCanceled);
} else if (inputParcel instanceof ConsolidateInputParcel) {
op = new ConsolidateOperation(outerThis, new DatabaseInteractor(outerThis), outerThis);
op = new ConsolidateOperation(outerThis, databaseInteractor, outerThis);
} else if (inputParcel instanceof KeybaseVerificationParcel) {
op = new KeybaseVerificationOperation(outerThis, new DatabaseInteractor(outerThis), outerThis);
op = new KeybaseVerificationOperation(outerThis, databaseInteractor, outerThis);
} else if (inputParcel instanceof InputDataParcel) {
op = new InputDataOperation(outerThis, new DatabaseInteractor(outerThis), outerThis);
op = new InputDataOperation(outerThis, databaseInteractor, outerThis);
} else if (inputParcel instanceof BenchmarkInputParcel) {
op = new BenchmarkOperation(outerThis, new DatabaseInteractor(outerThis), outerThis);
op = new BenchmarkOperation(outerThis, databaseInteractor, outerThis);
} else {
throw new AssertionError("Unrecognized input parcel in KeychainService!");
}

View File

@@ -35,8 +35,8 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
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.DatabaseReadWriteInteractor;
import org.sufficientlysecure.keychain.provider.KeychainContract;
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<ParcelableKeyRing> keyList,
CryptoInputParcel cryptoInputParcel) {
Log.d(Constants.TAG, "Starting normal update");
ImportOperation importOp = new ImportOperation(context, new DatabaseInteractor(context), null);
ImportOperation importOp = new ImportOperation(context, new DatabaseReadWriteInteractor(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 DatabaseInteractor(context), null, mCancelled)
new ImportOperation(context, new DatabaseReadWriteInteractor(context), null, mCancelled)
.execute(
new ImportKeyringParcel(
keyWrapper,

View File

@@ -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.DatabaseInteractor;
import org.sufficientlysecure.keychain.provider.DatabaseReadWriteInteractor;
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 DatabaseInteractor.NotFoundException {
private Passphrase getCachedPassphraseImpl(long masterKeyId, long subKeyId) throws DatabaseReadWriteInteractor.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 DatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId);
CachedPublicKeyRing keyRing = new DatabaseReadWriteInteractor(this).getCachedPublicKeyRing(masterKeyId);
SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId);
switch (keyType) {
case PASSPHRASE_EMPTY:
return new Passphrase("");
case UNAVAILABLE:
throw new DatabaseInteractor.NotFoundException("secret key for this subkey is not available");
throw new DatabaseReadWriteInteractor.NotFoundException("secret key for this subkey is not available");
case GNU_DUMMY:
throw new DatabaseInteractor.NotFoundException("secret key for stripped subkey is not available");
throw new DatabaseReadWriteInteractor.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 (DatabaseInteractor.NotFoundException e) {
} catch (DatabaseReadWriteInteractor.NotFoundException e) {
Log.e(Constants.TAG, "PassphraseCacheService: Passphrase for unknown key was requested!");
msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND;
}