rename ProviderHelper -> DatabaseInteractor
This commit is contained in:
@@ -27,7 +27,7 @@ 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.KeychainContract.Keys;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.DatabaseInteractor.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
/** This implementation of KeyRing provides a cached view of PublicKeyRing
|
||||
@@ -48,21 +48,21 @@ import org.sufficientlysecure.keychain.util.Log;
|
||||
*/
|
||||
public class CachedPublicKeyRing extends KeyRing {
|
||||
|
||||
final ProviderHelper mProviderHelper;
|
||||
final DatabaseInteractor mDatabaseInteractor;
|
||||
final Uri mUri;
|
||||
|
||||
public CachedPublicKeyRing(ProviderHelper providerHelper, Uri uri) {
|
||||
mProviderHelper = providerHelper;
|
||||
public CachedPublicKeyRing(DatabaseInteractor databaseInteractor, Uri uri) {
|
||||
mDatabaseInteractor = databaseInteractor;
|
||||
mUri = uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMasterKeyId() throws PgpKeyNotFoundException {
|
||||
try {
|
||||
Object data = mProviderHelper.getGenericData(mUri,
|
||||
KeychainContract.KeyRings.MASTER_KEY_ID, ProviderHelper.FIELD_TYPE_INTEGER);
|
||||
Object data = mDatabaseInteractor.getGenericData(mUri,
|
||||
KeychainContract.KeyRings.MASTER_KEY_ID, DatabaseInteractor.FIELD_TYPE_INTEGER);
|
||||
return (Long) data;
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
} catch (DatabaseInteractor.NotFoundException e) {
|
||||
throw new PgpKeyNotFoundException(e);
|
||||
}
|
||||
}
|
||||
@@ -85,10 +85,10 @@ public class CachedPublicKeyRing extends KeyRing {
|
||||
|
||||
public byte[] getFingerprint() throws PgpKeyNotFoundException {
|
||||
try {
|
||||
Object data = mProviderHelper.getGenericData(mUri,
|
||||
KeychainContract.KeyRings.FINGERPRINT, ProviderHelper.FIELD_TYPE_BLOB);
|
||||
Object data = mDatabaseInteractor.getGenericData(mUri,
|
||||
KeychainContract.KeyRings.FINGERPRINT, DatabaseInteractor.FIELD_TYPE_BLOB);
|
||||
return (byte[]) data;
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
} catch (DatabaseInteractor.NotFoundException e) {
|
||||
throw new PgpKeyNotFoundException(e);
|
||||
}
|
||||
}
|
||||
@@ -96,11 +96,11 @@ public class CachedPublicKeyRing extends KeyRing {
|
||||
@Override
|
||||
public String getPrimaryUserId() throws PgpKeyNotFoundException {
|
||||
try {
|
||||
Object data = mProviderHelper.getGenericData(mUri,
|
||||
Object data = mDatabaseInteractor.getGenericData(mUri,
|
||||
KeychainContract.KeyRings.USER_ID,
|
||||
ProviderHelper.FIELD_TYPE_STRING);
|
||||
DatabaseInteractor.FIELD_TYPE_STRING);
|
||||
return (String) data;
|
||||
} catch(ProviderHelper.NotFoundException e) {
|
||||
} catch(DatabaseInteractor.NotFoundException e) {
|
||||
throw new PgpKeyNotFoundException(e);
|
||||
}
|
||||
}
|
||||
@@ -111,22 +111,22 @@ public class CachedPublicKeyRing extends KeyRing {
|
||||
|
||||
public String getName() throws PgpKeyNotFoundException {
|
||||
try {
|
||||
Object data = mProviderHelper.getGenericData(mUri,
|
||||
Object data = mDatabaseInteractor.getGenericData(mUri,
|
||||
KeyRings.NAME,
|
||||
ProviderHelper.FIELD_TYPE_STRING);
|
||||
DatabaseInteractor.FIELD_TYPE_STRING);
|
||||
return (String) data;
|
||||
} catch(ProviderHelper.NotFoundException e) {
|
||||
} catch(DatabaseInteractor.NotFoundException e) {
|
||||
throw new PgpKeyNotFoundException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getEmail() throws PgpKeyNotFoundException {
|
||||
try {
|
||||
Object data = mProviderHelper.getGenericData(mUri,
|
||||
Object data = mDatabaseInteractor.getGenericData(mUri,
|
||||
KeyRings.EMAIL,
|
||||
ProviderHelper.FIELD_TYPE_STRING);
|
||||
DatabaseInteractor.FIELD_TYPE_STRING);
|
||||
return (String) data;
|
||||
} catch(ProviderHelper.NotFoundException e) {
|
||||
} catch(DatabaseInteractor.NotFoundException e) {
|
||||
throw new PgpKeyNotFoundException(e);
|
||||
}
|
||||
}
|
||||
@@ -134,11 +134,11 @@ public class CachedPublicKeyRing extends KeyRing {
|
||||
|
||||
public String getComment() throws PgpKeyNotFoundException {
|
||||
try {
|
||||
Object data = mProviderHelper.getGenericData(mUri,
|
||||
Object data = mDatabaseInteractor.getGenericData(mUri,
|
||||
KeyRings.COMMENT,
|
||||
ProviderHelper.FIELD_TYPE_STRING);
|
||||
DatabaseInteractor.FIELD_TYPE_STRING);
|
||||
return (String) data;
|
||||
} catch(ProviderHelper.NotFoundException e) {
|
||||
} catch(DatabaseInteractor.NotFoundException e) {
|
||||
throw new PgpKeyNotFoundException(e);
|
||||
}
|
||||
}
|
||||
@@ -146,11 +146,11 @@ public class CachedPublicKeyRing extends KeyRing {
|
||||
@Override
|
||||
public boolean isRevoked() throws PgpKeyNotFoundException {
|
||||
try {
|
||||
Object data = mProviderHelper.getGenericData(mUri,
|
||||
Object data = mDatabaseInteractor.getGenericData(mUri,
|
||||
KeychainContract.KeyRings.IS_REVOKED,
|
||||
ProviderHelper.FIELD_TYPE_INTEGER);
|
||||
DatabaseInteractor.FIELD_TYPE_INTEGER);
|
||||
return (Long) data > 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());
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user