wrapped-key-ring: use CachedKeyRing where possible
This commit is contained in:
@@ -2,8 +2,10 @@ package org.sufficientlysecure.keychain.provider;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
public class CachedPublicKeyRing extends KeyRing {
|
||||
|
||||
@@ -17,12 +19,30 @@ public class CachedPublicKeyRing extends KeyRing {
|
||||
|
||||
public long getMasterKeyId() throws PgpGeneralException {
|
||||
try {
|
||||
return mProviderHelper.getMasterKeyId(mUri);
|
||||
} catch(ProviderHelper.NotFoundException e) {
|
||||
Object data = mProviderHelper.getGenericData(mUri,
|
||||
KeychainContract.KeyRings.MASTER_KEY_ID, ProviderHelper.FIELD_TYPE_INTEGER);
|
||||
return (Long) data;
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
throw new PgpGeneralException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the master key id related to a given query. The id will either be extracted from the
|
||||
* query, which should work for all specific /key_rings/ queries, or will be queried if it can't.
|
||||
*/
|
||||
public long extractOrGetMasterKeyId() throws PgpGeneralException {
|
||||
// try extracting from the uri first
|
||||
String firstSegment = mUri.getPathSegments().get(1);
|
||||
if (!firstSegment.equals("find")) try {
|
||||
return Long.parseLong(firstSegment);
|
||||
} catch (NumberFormatException e) {
|
||||
// didn't work? oh well.
|
||||
Log.d(Constants.TAG, "Couldn't get masterKeyId from URI, querying...");
|
||||
}
|
||||
return getMasterKeyId();
|
||||
}
|
||||
|
||||
public String getPrimaryUserId() throws PgpGeneralException {
|
||||
try {
|
||||
Object data = mProviderHelper.getGenericData(mUri,
|
||||
|
||||
@@ -147,32 +147,6 @@ public class ProviderHelper {
|
||||
return getGenericData(KeyRings.buildUnifiedKeyRingUri(masterKeyId), proj, types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the master key id related to a given query. The id will either be extracted from the
|
||||
* query, which should work for all specific /key_rings/ queries, or will be queried if it can't.
|
||||
*/
|
||||
public long extractOrGetMasterKeyId(Uri queryUri)
|
||||
throws NotFoundException {
|
||||
// try extracting from the uri first
|
||||
String firstSegment = queryUri.getPathSegments().get(1);
|
||||
if (!firstSegment.equals("find")) try {
|
||||
return Long.parseLong(firstSegment);
|
||||
} catch (NumberFormatException e) {
|
||||
// didn't work? oh well.
|
||||
Log.d(Constants.TAG, "Couldn't get masterKeyId from URI, querying...");
|
||||
}
|
||||
return getMasterKeyId(queryUri);
|
||||
}
|
||||
|
||||
public long getMasterKeyId(Uri queryUri) throws NotFoundException {
|
||||
Object data = getGenericData(queryUri, KeyRings.MASTER_KEY_ID, FIELD_TYPE_INTEGER);
|
||||
if (data != null) {
|
||||
return (Long) data;
|
||||
} else {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public LongSparseArray<PGPKeyRing> getPGPKeyRings(Uri queryUri) {
|
||||
Cursor cursor = mContentResolver.query(queryUri,
|
||||
|
||||
Reference in New Issue
Block a user