slight cleanup

This commit is contained in:
Vincent Breitmoser
2017-09-23 00:46:06 +02:00
parent b814753b3b
commit 678a5c1562
42 changed files with 101 additions and 106 deletions

View File

@@ -42,7 +42,7 @@ public class KeyRepository {
OperationLog mLog;
int mIndent;
public static KeyRepository createDatabaseInteractor(Context context) {
public static KeyRepository create(Context context) {
ContentResolver contentResolver = context.getContentResolver();
LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(context);

View File

@@ -83,9 +83,7 @@ import org.sufficientlysecure.keychain.util.Utf8Util;
public class KeyWritableRepository extends KeyRepository {
private static final int MAX_CACHED_KEY_SIZE = 1024 * 50;
private final Context mContext;
public static KeyWritableRepository createDatabaseReadWriteInteractor(Context context) {
public static KeyWritableRepository create(Context context) {
LocalPublicKeyStorage localPublicKeyStorage = LocalPublicKeyStorage.getInstance(context);
return new KeyWritableRepository(context, localPublicKeyStorage);
@@ -99,8 +97,6 @@ public class KeyWritableRepository extends KeyRepository {
private KeyWritableRepository(
Context context, LocalPublicKeyStorage localPublicKeyStorage, OperationLog log, int indent) {
super(context.getContentResolver(), localPublicKeyStorage, log, indent);
mContext = context;
}
private LongSparseArray<CanonicalizedPublicKey> getTrustedMasterKeys() {

View File

@@ -104,7 +104,7 @@ public class OpenPgpService extends Service {
@Override
public void onCreate() {
super.onCreate();
mKeyRepository = KeyRepository.createDatabaseInteractor(this);
mKeyRepository = KeyRepository.create(this);
mApiDao = new ApiDataAccessObject(this);
mApiPermissionHelper = new ApiPermissionHelper(this, mApiDao);
mApiPendingIntentFactory = new ApiPendingIntentFactory(getBaseContext());
@@ -491,7 +491,7 @@ public class OpenPgpService extends Service {
return null;
}
// this will merge if the key already exists - no worries!
KeyWritableRepository.createDatabaseReadWriteInteractor(this).savePublicKeyRing(uncachedKeyRing);
KeyWritableRepository.create(this).savePublicKeyRing(uncachedKeyRing);
newMasterKeyId = uncachedKeyRing.getMasterKeyId();
} else {
newMasterKeyId = null;

View File

@@ -41,7 +41,7 @@ class RequestKeyPermissionPresenter {
ApiDataAccessObject apiDataAccessObject = new ApiDataAccessObject(context);
ApiPermissionHelper apiPermissionHelper = new ApiPermissionHelper(context, apiDataAccessObject);
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(context);
KeyRepository.create(context);
return new RequestKeyPermissionPresenter(context, apiDataAccessObject, apiPermissionHelper, packageManager,
keyRepository);

View File

@@ -112,7 +112,7 @@ public class KeychainService extends Service implements Progressable {
// just for brevity
KeychainService outerThis = KeychainService.this;
KeyWritableRepository databaseInteractor =
KeyWritableRepository.createDatabaseReadWriteInteractor(outerThis);
KeyWritableRepository.create(outerThis);
if (inputParcel instanceof SignEncryptParcel) {
op = new SignEncryptOperation(outerThis, databaseInteractor, outerThis, mActionCanceled);
} else if (inputParcel instanceof PgpDecryptVerifyInputParcel) {

View File

@@ -322,7 +322,7 @@ public class KeyserverSyncAdapterService extends Service {
CryptoInputParcel cryptoInputParcel) {
Log.d(Constants.TAG, "Starting normal update");
ImportOperation importOp = new ImportOperation(context,
KeyWritableRepository.createDatabaseReadWriteInteractor(context), null);
KeyWritableRepository.create(context), null);
return importOp.execute(
ImportKeyringParcel.createImportKeyringParcel(keyList,
Preferences.getPreferences(context).getPreferredKeyserver()),
@@ -381,7 +381,7 @@ public class KeyserverSyncAdapterService extends Service {
new OperationResult.OperationLog());
}
ImportKeyResult result =
new ImportOperation(context, KeyWritableRepository.createDatabaseReadWriteInteractor(context), null, mCancelled)
new ImportOperation(context, KeyWritableRepository.create(context), null, mCancelled)
.execute(
ImportKeyringParcel.createImportKeyringParcel(
keyWrapper,

View File

@@ -245,7 +245,7 @@ public class PassphraseCacheService extends Service {
+ masterKeyId + ", subKeyId " + subKeyId);
// get the type of key (from the database)
CachedPublicKeyRing keyRing = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(masterKeyId);
CachedPublicKeyRing keyRing = KeyRepository.create(this).getCachedPublicKeyRing(masterKeyId);
SecretKeyType keyType = keyRing.getSecretKeyType(subKeyId);
switch (keyType) {

View File

@@ -214,7 +214,7 @@ public class CertifyFingerprintFragment extends LoaderFragment implements
private void certify(Uri dataUri) {
long keyId = 0;
try {
keyId = KeyRepository.createDatabaseInteractor(getContext())
keyId = KeyRepository.create(getContext())
.getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) {

View File

@@ -70,7 +70,7 @@ public class CertifyKeyFragment
if (certifyKeyId != Constants.key.none) {
try {
CachedPublicKeyRing key = (KeyRepository
.createDatabaseInteractor(getContext()))
.create(getContext()))
.getCachedPublicKeyRing(certifyKeyId);
if (key.canCertify()) {
mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId);

View File

@@ -430,7 +430,7 @@ public class CreateKeyFinalFragment extends Fragment {
CreateKeyActivity activity = (CreateKeyActivity) getActivity();
SaveKeyringParcel.Builder builder;
CachedPublicKeyRing key = (KeyRepository.createDatabaseInteractor(getContext()))
CachedPublicKeyRing key = (KeyRepository.create(getContext()))
.getCachedPublicKeyRing(saveKeyResult.mMasterKeyId);
try {
builder = SaveKeyringParcel.buildChangeKeyringParcel(key.getMasterKeyId(), key.getFingerprint());

View File

@@ -194,7 +194,7 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
try {
Intent viewKeyIntent = new Intent(getActivity(), ViewKeyActivity.class);
long masterKeyId = KeyRepository.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(
long masterKeyId = KeyRepository.create(getContext()).getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId)
).getMasterKeyId();
viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId));

View File

@@ -89,7 +89,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
if (mMasterKeyIds.length == 1 && mHasSecret) {
// if mMasterKeyIds.length == 0 we let the DeleteOperation respond
try {
HashMap<String, Object> data = KeyRepository.createDatabaseInteractor(this).getUnifiedData(
HashMap<String, Object> data = KeyRepository.create(this).getUnifiedData(
mMasterKeyIds[0], new String[]{
KeychainContract.KeyRings.NAME,
KeychainContract.KeyRings.IS_REVOKED
@@ -272,7 +272,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
long masterKeyId = masterKeyIds[0];
try {
HashMap<String, Object> data = KeyRepository.createDatabaseInteractor(getContext())
HashMap<String, Object> data = KeyRepository.create(getContext())
.getUnifiedData(
masterKeyId, new String[]{
KeychainContract.KeyRings.NAME,

View File

@@ -170,7 +170,7 @@ public class EditIdentitiesFragment extends Fragment
try {
Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri);
CachedPublicKeyRing keyRing =
KeyRepository.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(secretUri);
KeyRepository.create(getContext()).getCachedPublicKeyRing(secretUri);
long masterKeyId = keyRing.getMasterKeyId();
// check if this is a master secret key we can work with

View File

@@ -201,7 +201,7 @@ public class EditKeyFragment extends QueueingCryptoOperationFragment<SaveKeyring
try {
Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri);
CachedPublicKeyRing keyRing =
KeyRepository.createDatabaseInteractor(getContext()).getCachedPublicKeyRing(secretUri);
KeyRepository.create(getContext()).getCachedPublicKeyRing(secretUri);
long masterKeyId = keyRing.getMasterKeyId();
// check if this is a master secret key we can work with

View File

@@ -118,7 +118,7 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mKeyRepository = KeyRepository.createDatabaseInteractor(getContext());
mKeyRepository = KeyRepository.create(getContext());
// preselect keys given, from state or arguments
if (savedInstanceState == null) {

View File

@@ -477,7 +477,7 @@ public class KeyListFragment extends RecyclerFragment<KeySectionedListAdapter>
}
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(getContext());
KeyRepository.create(getContext());
Cursor cursor = keyRepository.getContentResolver().query(
KeyRings.buildUnifiedKeyRingsUri(), new String[]{
KeyRings.FINGERPRINT

View File

@@ -112,7 +112,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
// handle empty passphrases by directly returning an empty crypto input parcel
try {
CachedPublicKeyRing pubRing =
KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId());
KeyRepository.create(this).getCachedPublicKeyRing(requiredInput.getMasterKeyId());
// use empty passphrase for empty passphrase
if (pubRing.getSecretKeyType(requiredInput.getSubKeyId()) == SecretKeyType.PASSPHRASE_EMPTY) {
// also return passphrase back to activity
@@ -234,7 +234,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
long subKeyId = mRequiredInput.getSubKeyId();
KeyRepository helper =
KeyRepository.createDatabaseInteractor(getContext());
KeyRepository.create(getContext());
CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing(
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
// yes the inner try/catch block is necessary, otherwise the final variable
@@ -454,7 +454,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
Long subKeyId = mRequiredInput.getSubKeyId();
CanonicalizedSecretKeyRing secretKeyRing =
KeyRepository.createDatabaseInteractor(getContext()).getCanonicalizedSecretKeyRing(
KeyRepository.create(getContext()).getCanonicalizedSecretKeyRing(
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
CanonicalizedSecretKey secretKeyToUnlock =
secretKeyRing.getSecretKey(subKeyId);

View File

@@ -74,7 +74,7 @@ public class QrCodeViewActivity extends BaseActivity {
}
});
KeyRepository keyRepository = KeyRepository.createDatabaseInteractor(this);
KeyRepository keyRepository = KeyRepository.create(this);
try {
byte[] blob = keyRepository.getCachedPublicKeyRing(dataUri).getFingerprint();
if (blob == null) {

View File

@@ -106,7 +106,7 @@ public class SafeSlingerActivity extends BaseActivity
// retrieve public key blob and start SafeSlinger
Uri uri = KeychainContract.KeyRingData.buildPublicKeyRingUri(masterKeyId);
try {
byte[] keyBlob = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(uri).getEncoded();
byte[] keyBlob = KeyRepository.create(this).getCachedPublicKeyRing(uri).getEncoded();
Intent slingerIntent = new Intent(this, ExchangeActivity.class);

View File

@@ -197,7 +197,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity {
}
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(this);
KeyRepository.create(this);
CanonicalizedPublicKeyRing publicKeyRing;
try {
publicKeyRing = keyRepository.getCanonicalizedPublicKeyRing(
@@ -237,7 +237,7 @@ public class SecurityTokenOperationActivity extends BaseSecurityTokenActivity {
mSecurityTokenHelper.setAdminPin(new Passphrase("12345678"));
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(this);
KeyRepository.create(this);
CanonicalizedSecretKeyRing secretKeyRing;
try {
secretKeyRing = keyRepository.getCanonicalizedSecretKeyRing(

View File

@@ -79,7 +79,7 @@ public class SettingsKeyserverFragment extends Fragment implements RecyclerItemC
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
databaseReadWriteInteractor = KeyWritableRepository.createDatabaseReadWriteInteractor(getContext());
databaseReadWriteInteractor = KeyWritableRepository.create(getContext());
return inflater.inflate(R.layout.settings_keyserver_fragment, null);
}

View File

@@ -189,7 +189,7 @@ public class ViewCertActivity extends BaseActivity
try {
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(ViewCertActivity.this);
KeyRepository.create(ViewCertActivity.this);
long signerMasterKeyId = keyRepository.getCachedPublicKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(mCertifierKeyId)).getMasterKeyId();
viewIntent.setData(KeyRings.buildGenericKeyRingUri(signerMasterKeyId));

View File

@@ -88,7 +88,7 @@ public class ViewKeyAdvActivity extends BaseActivity implements
}
});
mKeyRepository = KeyRepository.createDatabaseInteractor(this);
mKeyRepository = KeyRepository.create(this);
mViewPager = (ViewPager) findViewById(R.id.pager);
mSlidingTabLayout = (PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout);

View File

@@ -181,7 +181,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
private void startSafeSlinger(Uri dataUri) {
long keyId = 0;
try {
keyId = KeyRepository.createDatabaseInteractor(getContext())
keyId = KeyRepository.create(getContext())
.getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) {
@@ -198,7 +198,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
return;
}
KeyRepository keyRepository =
KeyRepository.createDatabaseInteractor(getContext());
KeyRepository.create(getContext());
try {
long masterKeyId = keyRepository.getCachedPublicKeyRing(mDataUri).extractOrGetMasterKeyId();
@@ -436,7 +436,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements
private void uploadToKeyserver() {
long keyId;
try {
keyId = KeyRepository.createDatabaseInteractor(getContext())
keyId = KeyRepository.create(getContext())
.getCachedPublicKeyRing(mDataUri)
.extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) {

View File

@@ -75,7 +75,7 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
mListener = listener;
mNonInteractive = nonInteractive;
mKeyRepository = KeyRepository.createDatabaseInteractor(activity);
mKeyRepository = KeyRepository.create(activity);
}
public void setData(List<ImportKeysListEntry> data) {

View File

@@ -467,7 +467,7 @@ public class LinkedIdViewFragment extends CryptoOperationFragment implements
byte[] fingerprint;
try {
fingerprint = KeyRepository.createDatabaseInteractor(activity).getCachedPublicKeyRing(
fingerprint = KeyRepository.create(activity).getCachedPublicKeyRing(
mMasterKeyId).getFingerprint();
} catch (PgpKeyNotFoundException e) {
throw new IllegalStateException("Key to verify linked id for must exist in db!");

View File

@@ -175,7 +175,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mKeyRepository = KeyRepository.createDatabaseInteractor(this);
mKeyRepository = KeyRepository.create(this);
mImportOpHelper = new CryptoOperationHelper<>(1, this, this, null);
setTitle(null);
@@ -656,7 +656,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
return;
}
try {
long keyId = KeyRepository.createDatabaseInteractor(this)
long keyId = KeyRepository.create(this)
.getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId();
long[] encryptionKeyIds = new long[]{keyId};
@@ -680,7 +680,7 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
private void startSafeSlinger(Uri dataUri) {
long keyId = 0;
try {
keyId = KeyRepository.createDatabaseInteractor(this)
keyId = KeyRepository.create(this)
.getCachedPublicKeyRing(dataUri)
.extractOrGetMasterKeyId();
} catch (PgpKeyNotFoundException e) {

View File

@@ -58,7 +58,7 @@ public class LinkedIdWizard extends BaseActivity {
try {
Uri uri = getIntent().getData();
uri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(uri);
CachedPublicKeyRing ring = KeyRepository.createDatabaseInteractor(this).getCachedPublicKeyRing(uri);
CachedPublicKeyRing ring = KeyRepository.create(this).getCachedPublicKeyRing(uri);
if (!ring.hasAnySecret()) {
Log.e(Constants.TAG, "Linked Identities can only be added to secret keys!");
finish();

View File

@@ -98,7 +98,7 @@ public abstract class PublicKeyRetrievalLoader extends AsyncTaskLoader<KeyRetrie
LocalKeyLookupLoader(Context context, List<byte[]> fingerprints) {
super(context, fingerprints);
this.keyRepository = KeyRepository.createDatabaseInteractor(context);
this.keyRepository = KeyRepository.create(context);
}
@Override

View File

@@ -96,7 +96,7 @@ public class TransferPresenter implements KeyTransferCallback, LoaderCallbacks<L
this.view = view;
this.loaderManager = loaderManager;
this.loaderId = loaderId;
this.databaseInteractor = KeyRepository.createDatabaseInteractor(context);
this.databaseInteractor = KeyRepository.create(context);
secretKeyAdapter = new TransferKeyAdapter(context, LayoutInflater.from(context), this);
view.setSecretKeyAdapter(secretKeyAdapter);