mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-16 13:55:03 -05:00
KeyListAdapter is working basically, Provider refactored
This commit is contained in:
parent
4704e2faf4
commit
691d888e92
@ -74,113 +74,97 @@ public class ApgContract {
|
||||
public static final String PATH_USER_IDS = "user_ids";
|
||||
public static final String PATH_KEYS = "keys";
|
||||
|
||||
public static class PublicKeyRings implements KeyRingsColumns, BaseColumns {
|
||||
public static class KeyRings implements KeyRingsColumns, BaseColumns {
|
||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
|
||||
.appendPath(BASE_KEY_RINGS).appendPath(PATH_PUBLIC).build();
|
||||
.appendPath(BASE_KEY_RINGS).build();
|
||||
|
||||
/** Use if multiple items get returned */
|
||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.public.key_ring";
|
||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.key_ring";
|
||||
|
||||
/** Use if a single item is returned */
|
||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.public.key_ring";
|
||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.key_ring";
|
||||
|
||||
public static Uri buildPublicKeyRingsUri() {
|
||||
return CONTENT_URI.buildUpon().build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC).build();
|
||||
}
|
||||
|
||||
public static Uri buildPublicKeyRingsUri(String keyRingRowId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(keyRingRowId).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC).appendPath(keyRingRowId).build();
|
||||
}
|
||||
|
||||
public static Uri buildPublicKeyRingsByMasterKeyIdUri(String masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_BY_MASTER_KEY_ID)
|
||||
.appendPath(masterKeyId).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC)
|
||||
.appendPath(PATH_BY_MASTER_KEY_ID).appendPath(masterKeyId).build();
|
||||
}
|
||||
|
||||
public static Uri buildPublicKeyRingsByKeyIdUri(String keyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_BY_KEY_ID).appendPath(keyId).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC).appendPath(PATH_BY_KEY_ID)
|
||||
.appendPath(keyId).build();
|
||||
}
|
||||
|
||||
public static Uri buildPublicKeyRingsByEmailsUri(String emails) {
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_BY_EMAILS).appendPath(emails).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC).appendPath(PATH_BY_EMAILS)
|
||||
.appendPath(emails).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecretKeyRings implements KeyRingsColumns, BaseColumns {
|
||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
|
||||
.appendPath(BASE_KEY_RINGS).appendPath(PATH_SECRET).build();
|
||||
|
||||
/** Use if multiple items get returned */
|
||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.secret.key_ring";
|
||||
|
||||
/** Use if a single item is returned */
|
||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.secret.key_ring";
|
||||
|
||||
public static Uri buildSecretKeyRingsUri() {
|
||||
return CONTENT_URI.buildUpon().build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).build();
|
||||
}
|
||||
|
||||
public static Uri buildSecretKeyRingsUri(String keyRingRowId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(keyRingRowId).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).appendPath(keyRingRowId).build();
|
||||
}
|
||||
|
||||
public static Uri buildSecretKeyRingsByMasterKeyIdUri(String masterKeyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_BY_MASTER_KEY_ID)
|
||||
.appendPath(masterKeyId).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET)
|
||||
.appendPath(PATH_BY_MASTER_KEY_ID).appendPath(masterKeyId).build();
|
||||
}
|
||||
|
||||
public static Uri buildSecretKeyRingsByKeyIdUri(String keyId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_BY_KEY_ID).appendPath(keyId).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).appendPath(PATH_BY_KEY_ID)
|
||||
.appendPath(keyId).build();
|
||||
}
|
||||
|
||||
public static Uri buildSecretKeyRingsByEmailsUri(String emails) {
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_BY_EMAILS).appendPath(emails).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).appendPath(PATH_BY_EMAILS)
|
||||
.appendPath(emails).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PublicKeys implements KeysColumns, BaseColumns {
|
||||
public static class Keys implements KeysColumns, BaseColumns {
|
||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
|
||||
.appendPath(BASE_KEY_RINGS).appendPath(PATH_PUBLIC).build();
|
||||
.appendPath(BASE_KEY_RINGS).build();
|
||||
|
||||
/** Use if multiple items get returned */
|
||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.public.key";
|
||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.key";
|
||||
|
||||
/** Use if a single item is returned */
|
||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.public.key";
|
||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.key";
|
||||
|
||||
public static Uri buildPublicKeysUri(String keyRingRowId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(keyRingRowId).appendPath(PATH_KEYS).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC).appendPath(keyRingRowId)
|
||||
.appendPath(PATH_KEYS).build();
|
||||
}
|
||||
|
||||
public static Uri buildPublicKeysUri(String keyRingRowId, String keyRowId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(keyRingRowId).appendPath(PATH_KEYS)
|
||||
.appendPath(keyRowId).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC).appendPath(keyRingRowId)
|
||||
.appendPath(PATH_KEYS).appendPath(keyRowId).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecretKeys implements KeysColumns, BaseColumns {
|
||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
|
||||
.appendPath(BASE_KEY_RINGS).appendPath(PATH_SECRET).build();
|
||||
|
||||
/** Use if multiple items get returned */
|
||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.secret.key";
|
||||
|
||||
/** Use if a single item is returned */
|
||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.secret.key";
|
||||
|
||||
public static Uri buildSecretKeysUri(String keyRingRowId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(keyRingRowId).appendPath(PATH_KEYS).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).appendPath(keyRingRowId)
|
||||
.appendPath(PATH_KEYS).build();
|
||||
}
|
||||
|
||||
public static Uri buildSecretKeysUri(String keyRingRowId, String keyRowId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(keyRingRowId).appendPath(PATH_KEYS)
|
||||
.appendPath(keyRowId).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).appendPath(keyRingRowId)
|
||||
.appendPath(PATH_KEYS).appendPath(keyRowId).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PublicUserIds implements UserIdsColumns, BaseColumns {
|
||||
public static class UserIds implements UserIdsColumns, BaseColumns {
|
||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
|
||||
.appendPath(BASE_KEY_RINGS).appendPath(PATH_PUBLIC).build();
|
||||
.appendPath(BASE_KEY_RINGS).build();
|
||||
|
||||
/** Use if multiple items get returned */
|
||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.user_id";
|
||||
@ -189,34 +173,23 @@ public class ApgContract {
|
||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.user_id";
|
||||
|
||||
public static Uri buildPublicUserIdsUri(String keyRingRowId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(keyRingRowId).appendPath(PATH_USER_IDS)
|
||||
.build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC).appendPath(keyRingRowId)
|
||||
.appendPath(PATH_USER_IDS).build();
|
||||
}
|
||||
|
||||
public static Uri buildPublicUserIdsUri(String keyRingRowId, String userIdRowId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(keyRingRowId).appendPath(PATH_USER_IDS)
|
||||
.appendPath(userIdRowId).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_PUBLIC).appendPath(keyRingRowId)
|
||||
.appendPath(PATH_USER_IDS).appendPath(userIdRowId).build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecretUserIds implements UserIdsColumns, BaseColumns {
|
||||
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
|
||||
.appendPath(BASE_KEY_RINGS).appendPath(PATH_SECRET).build();
|
||||
|
||||
/** Use if multiple items get returned */
|
||||
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.user_id";
|
||||
|
||||
/** Use if a single item is returned */
|
||||
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.user_id";
|
||||
|
||||
public static Uri buildSecretUserIdsUri(String keyRingRowId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(keyRingRowId).appendPath(PATH_USER_IDS)
|
||||
.build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).appendPath(keyRingRowId)
|
||||
.appendPath(PATH_USER_IDS).build();
|
||||
}
|
||||
|
||||
public static Uri buildSecretUserIdsUri(String keyRingRowId, String userIdRowId) {
|
||||
return CONTENT_URI.buildUpon().appendPath(keyRingRowId).appendPath(PATH_USER_IDS)
|
||||
.appendPath(userIdRowId).build();
|
||||
return CONTENT_URI.buildUpon().appendPath(PATH_SECRET).appendPath(keyRingRowId)
|
||||
.appendPath(PATH_USER_IDS).appendPath(userIdRowId).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,15 +23,12 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.KeyRingsColumns;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.KeyTypes;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.KeysColumns;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicKeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicKeys;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicUserIds;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.SecretKeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.SecretKeys;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.SecretUserIds;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.UserIds;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.Keys;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.UserIdsColumns;
|
||||
import org.thialfihar.android.apg.provider.ApgDatabase.Tables;
|
||||
import org.thialfihar.android.apg.util.Log;
|
||||
@ -189,7 +186,7 @@ public class ApgProvider extends ContentProvider {
|
||||
* data stream
|
||||
*
|
||||
* <pre>
|
||||
* data/*
|
||||
* data / _
|
||||
* </pre>
|
||||
*/
|
||||
matcher.addURI(authority, ApgContract.BASE_DATA + "/*", DATA_STREAM);
|
||||
@ -214,45 +211,33 @@ public class ApgProvider extends ContentProvider {
|
||||
switch (match) {
|
||||
case PUBLIC_KEY_RING:
|
||||
case PUBLIC_KEY_RING_BY_EMAILS:
|
||||
return PublicKeyRings.CONTENT_TYPE;
|
||||
case SECRET_KEY_RING:
|
||||
case SECRET_KEY_RING_BY_EMAILS:
|
||||
return KeyRings.CONTENT_TYPE;
|
||||
|
||||
case PUBLIC_KEY_RING_BY_ROW_ID:
|
||||
case PUBLIC_KEY_RING_BY_MASTER_KEY_ID:
|
||||
case PUBLIC_KEY_RING_BY_KEY_ID:
|
||||
return PublicKeyRings.CONTENT_ITEM_TYPE;
|
||||
|
||||
case PUBLIC_KEY_RING_KEY:
|
||||
return PublicKeys.CONTENT_TYPE;
|
||||
|
||||
case PUBLIC_KEY_RING_KEY_BY_ROW_ID:
|
||||
return PublicKeys.CONTENT_ITEM_TYPE;
|
||||
|
||||
case PUBLIC_KEY_RING_USER_ID:
|
||||
return PublicUserIds.CONTENT_TYPE;
|
||||
|
||||
case PUBLIC_KEY_RING_USER_ID_BY_ROW_ID:
|
||||
return PublicUserIds.CONTENT_ITEM_TYPE;
|
||||
|
||||
case SECRET_KEY_RING:
|
||||
case SECRET_KEY_RING_BY_EMAILS:
|
||||
return SecretKeyRings.CONTENT_TYPE;
|
||||
|
||||
case SECRET_KEY_RING_BY_ROW_ID:
|
||||
case SECRET_KEY_RING_BY_MASTER_KEY_ID:
|
||||
case SECRET_KEY_RING_BY_KEY_ID:
|
||||
return SecretKeyRings.CONTENT_ITEM_TYPE;
|
||||
return KeyRings.CONTENT_ITEM_TYPE;
|
||||
|
||||
case PUBLIC_KEY_RING_KEY:
|
||||
case SECRET_KEY_RING_KEY:
|
||||
return SecretKeys.CONTENT_TYPE;
|
||||
return Keys.CONTENT_TYPE;
|
||||
|
||||
case PUBLIC_KEY_RING_KEY_BY_ROW_ID:
|
||||
case SECRET_KEY_RING_KEY_BY_ROW_ID:
|
||||
return SecretKeys.CONTENT_ITEM_TYPE;
|
||||
return Keys.CONTENT_ITEM_TYPE;
|
||||
|
||||
case PUBLIC_KEY_RING_USER_ID:
|
||||
case SECRET_KEY_RING_USER_ID:
|
||||
return SecretUserIds.CONTENT_TYPE;
|
||||
return UserIds.CONTENT_TYPE;
|
||||
|
||||
case PUBLIC_KEY_RING_USER_ID_BY_ROW_ID:
|
||||
case SECRET_KEY_RING_USER_ID_BY_ROW_ID:
|
||||
return SecretUserIds.CONTENT_ITEM_TYPE;
|
||||
return UserIds.CONTENT_ITEM_TYPE;
|
||||
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
||||
@ -314,6 +299,8 @@ public class ApgProvider extends ContentProvider {
|
||||
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
|
||||
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
|
||||
+ KeyRingsColumns.MASTER_KEY_ID);
|
||||
projectionMap.put(KeyRingsColumns.KEY_RING_DATA, Tables.KEY_RINGS + "."
|
||||
+ KeyRingsColumns.KEY_RING_DATA);
|
||||
projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "." + UserIdsColumns.USER_ID);
|
||||
|
||||
qb.setProjectionMap(projectionMap);
|
||||
@ -338,6 +325,7 @@ public class ApgProvider extends ContentProvider {
|
||||
case PUBLIC_KEY_RING:
|
||||
case SECRET_KEY_RING:
|
||||
qb = buildKeyRingQuery(qb, projectionMap, match, sortOrder);
|
||||
|
||||
if (TextUtils.isEmpty(sortOrder)) {
|
||||
sortOrder = Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC";
|
||||
}
|
||||
@ -372,30 +360,15 @@ public class ApgProvider extends ContentProvider {
|
||||
|
||||
case SECRET_KEY_RING_BY_KEY_ID:
|
||||
case PUBLIC_KEY_RING_BY_KEY_ID:
|
||||
qb.appendWhere(Tables.KEY_RINGS + "." + KeyRingsColumns.TYPE + " = ");
|
||||
qb.appendWhereEscapeString(Integer.toString(getKeyType(match)));
|
||||
qb = buildKeyRingQuery(qb, projectionMap, match, sortOrder);
|
||||
|
||||
qb.setTables(Tables.KEYS + " AS tmp INNER JOIN " + Tables.KEY_RINGS + " ON ("
|
||||
+ Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + "tmp."
|
||||
+ KeysColumns.KEY_RING_ROW_ID + ")" + " INNER JOIN " + Tables.KEYS + " ON "
|
||||
+ "(" + Tables.KEY_RINGS + "." + BaseColumns._ID + " = " + Tables.KEYS + "."
|
||||
+ KeysColumns.KEY_RING_ROW_ID + " AND " + Tables.KEYS + "."
|
||||
+ KeysColumns.IS_MASTER_KEY + " = '1'" + ") " + " INNER JOIN "
|
||||
+ Tables.USER_IDS + " ON " + "(" + Tables.KEY_RINGS + "." + BaseColumns._ID
|
||||
+ " = " + Tables.USER_IDS + "." + UserIdsColumns.KEY_RING_ROW_ID + " AND "
|
||||
+ Tables.USER_IDS + "." + UserIdsColumns.RANK + " = '0')");
|
||||
|
||||
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
|
||||
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
|
||||
+ KeyRingsColumns.MASTER_KEY_ID);
|
||||
projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "."
|
||||
+ UserIdsColumns.USER_ID);
|
||||
|
||||
qb.setProjectionMap(projectionMap);
|
||||
|
||||
qb.appendWhere(" AND tmp." + KeysColumns.KEY_ID + " = ");
|
||||
qb.appendWhere(" AND " + Tables.KEYS + KeysColumns.KEY_ID + " = ");
|
||||
qb.appendWhereEscapeString(uri.getLastPathSegment());
|
||||
|
||||
if (TextUtils.isEmpty(sortOrder)) {
|
||||
sortOrder = Tables.USER_IDS + "." + UserIdsColumns.USER_ID + " ASC";
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SECRET_KEY_RING_BY_EMAILS:
|
||||
@ -414,6 +387,8 @@ public class ApgProvider extends ContentProvider {
|
||||
projectionMap.put(BaseColumns._ID, Tables.KEY_RINGS + "." + BaseColumns._ID);
|
||||
projectionMap.put(KeyRingsColumns.MASTER_KEY_ID, Tables.KEY_RINGS + "."
|
||||
+ KeyRingsColumns.MASTER_KEY_ID);
|
||||
projectionMap.put(KeyRingsColumns.KEY_RING_DATA, Tables.KEY_RINGS + "."
|
||||
+ KeyRingsColumns.KEY_RING_DATA);
|
||||
projectionMap.put(UserIdsColumns.USER_ID, Tables.USER_IDS + "."
|
||||
+ UserIdsColumns.USER_ID);
|
||||
|
||||
@ -532,41 +507,41 @@ public class ApgProvider extends ContentProvider {
|
||||
|
||||
switch (match) {
|
||||
case PUBLIC_KEY_RING:
|
||||
values.put(PublicKeyRings.TYPE, KeyTypes.PUBLIC);
|
||||
values.put(KeyRings.TYPE, KeyTypes.PUBLIC);
|
||||
|
||||
rowId = db.insertOrThrow(Tables.KEY_RINGS, null, values);
|
||||
rowUri = PublicKeyRings.buildPublicKeyRingsUri(Long.toString(rowId));
|
||||
rowUri = KeyRings.buildPublicKeyRingsUri(Long.toString(rowId));
|
||||
|
||||
break;
|
||||
case PUBLIC_KEY_RING_KEY:
|
||||
values.put(PublicKeys.TYPE, KeyTypes.PUBLIC);
|
||||
values.put(Keys.TYPE, KeyTypes.PUBLIC);
|
||||
|
||||
rowId = db.insertOrThrow(Tables.KEYS, null, values);
|
||||
rowUri = PublicKeys.buildPublicKeysUri(Long.toString(rowId));
|
||||
rowUri = Keys.buildPublicKeysUri(Long.toString(rowId));
|
||||
|
||||
break;
|
||||
case PUBLIC_KEY_RING_USER_ID:
|
||||
rowId = db.insertOrThrow(Tables.USER_IDS, null, values);
|
||||
rowUri = PublicUserIds.buildPublicUserIdsUri(Long.toString(rowId));
|
||||
rowUri = UserIds.buildPublicUserIdsUri(Long.toString(rowId));
|
||||
|
||||
break;
|
||||
case SECRET_KEY_RING:
|
||||
values.put(SecretKeyRings.TYPE, KeyTypes.SECRET);
|
||||
values.put(KeyRings.TYPE, KeyTypes.SECRET);
|
||||
|
||||
rowId = db.insertOrThrow(Tables.KEY_RINGS, null, values);
|
||||
rowUri = SecretKeyRings.buildSecretKeyRingsUri(Long.toString(rowId));
|
||||
rowUri = KeyRings.buildSecretKeyRingsUri(Long.toString(rowId));
|
||||
|
||||
break;
|
||||
case SECRET_KEY_RING_KEY:
|
||||
values.put(SecretKeys.TYPE, KeyTypes.SECRET);
|
||||
values.put(Keys.TYPE, KeyTypes.SECRET);
|
||||
|
||||
rowId = db.insertOrThrow(Tables.KEYS, null, values);
|
||||
rowUri = SecretKeys.buildSecretKeysUri(Long.toString(rowId));
|
||||
rowUri = Keys.buildSecretKeysUri(Long.toString(rowId));
|
||||
|
||||
break;
|
||||
case SECRET_KEY_RING_USER_ID:
|
||||
rowId = db.insertOrThrow(Tables.USER_IDS, null, values);
|
||||
rowUri = SecretUserIds.buildSecretUserIdsUri(Long.toString(rowId));
|
||||
rowUri = UserIds.buildSecretUserIdsUri(Long.toString(rowId));
|
||||
|
||||
break;
|
||||
default:
|
||||
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.spongycastle.openpgp.PGPKeyRing;
|
||||
import org.spongycastle.openpgp.PGPPublicKey;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
@ -12,12 +13,9 @@ import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.helper.PGPConversionHelper;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicKeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicKeys;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicUserIds;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.SecretKeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.SecretKeys;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.SecretUserIds;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.UserIds;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.Keys;
|
||||
import org.thialfihar.android.apg.util.IterableIterator;
|
||||
import org.thialfihar.android.apg.util.Log;
|
||||
|
||||
@ -32,63 +30,20 @@ import android.os.RemoteException;
|
||||
|
||||
public class ProviderHelper {
|
||||
|
||||
//
|
||||
// public static HashMap<String, String> sKeyRingsProjection;
|
||||
// public static HashMap<String, String> sKeysProjection;
|
||||
// public static HashMap<String, String> sUserIdsProjection;
|
||||
//
|
||||
// private SQLiteDatabase mDb = null;
|
||||
// private int mStatus = 0;
|
||||
//
|
||||
// static {
|
||||
// sKeyRingsProjection = new HashMap<String, String>();
|
||||
// sKeyRingsProjection.put(KeyRings._ID, KeyRings._ID);
|
||||
// sKeyRingsProjection.put(KeyRings.MASTER_KEY_ID, KeyRings.MASTER_KEY_ID);
|
||||
// sKeyRingsProjection.put(KeyRings.TYPE, KeyRings.TYPE);
|
||||
// sKeyRingsProjection.put(KeyRings.WHO_ID, KeyRings.WHO_ID);
|
||||
// sKeyRingsProjection.put(KeyRings.KEY_RING_DATA, KeyRings.KEY_RING_DATA);
|
||||
//
|
||||
// sKeysProjection = new HashMap<String, String>();
|
||||
// sKeysProjection.put(Keys._ID, Keys._ID);
|
||||
// sKeysProjection.put(Keys.KEY_ID, Keys.KEY_ID);
|
||||
// sKeysProjection.put(Keys.TYPE, Keys.TYPE);
|
||||
// sKeysProjection.put(Keys.IS_MASTER_KEY, Keys.IS_MASTER_KEY);
|
||||
// sKeysProjection.put(Keys.ALGORITHM, Keys.ALGORITHM);
|
||||
// sKeysProjection.put(Keys.KEY_SIZE, Keys.KEY_SIZE);
|
||||
// sKeysProjection.put(Keys.CAN_SIGN, Keys.CAN_SIGN);
|
||||
// sKeysProjection.put(Keys.CAN_ENCRYPT, Keys.CAN_ENCRYPT);
|
||||
// sKeysProjection.put(Keys.IS_REVOKED, Keys.IS_REVOKED);
|
||||
// sKeysProjection.put(Keys.CREATION, Keys.CREATION);
|
||||
// sKeysProjection.put(Keys.EXPIRY, Keys.EXPIRY);
|
||||
// sKeysProjection.put(Keys.KEY_DATA, Keys.KEY_DATA);
|
||||
// sKeysProjection.put(Keys.RANK, Keys.RANK);
|
||||
//
|
||||
// sUserIdsProjection = new HashMap<String, String>();
|
||||
// sUserIdsProjection.put(UserIds._ID, UserIds._ID);
|
||||
// sUserIdsProjection.put(UserIds.KEY_ID, UserIds.KEY_ID);
|
||||
// sUserIdsProjection.put(UserIds.USER_ID, UserIds.USER_ID);
|
||||
// sUserIdsProjection.put(UserIds.RANK, UserIds.RANK);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Retrieves the actual PGPPublicKeyRing object from the database blob associated with the
|
||||
* maserKeyId
|
||||
* Private helper method to get PGPKeyRing from database
|
||||
*
|
||||
* @param context
|
||||
* @param masterKeyId
|
||||
* @param queryUri
|
||||
* @return
|
||||
*/
|
||||
public static PGPPublicKeyRing getPGPPublicKeyRingByMasterKeyId(Context context,
|
||||
long masterKeyId) {
|
||||
Uri queryUri = PublicKeyRings.buildPublicKeyRingsByMasterKeyIdUri(Long
|
||||
.toString(masterKeyId));
|
||||
Cursor cursor = context.getContentResolver()
|
||||
.query(queryUri, new String[] { PublicKeyRings._ID, PublicKeyRings.KEY_RING_DATA },
|
||||
null, null, null);
|
||||
private static PGPKeyRing getPGPKeyRing(Context context, Uri queryUri) {
|
||||
Cursor cursor = context.getContentResolver().query(queryUri,
|
||||
new String[] { KeyRings._ID, KeyRings.KEY_RING_DATA }, null, null, null);
|
||||
|
||||
PGPPublicKeyRing keyRing = null;
|
||||
PGPKeyRing keyRing = null;
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
int keyRingDataCol = cursor.getColumnIndex(PublicKeyRings.KEY_RING_DATA);
|
||||
int keyRingDataCol = cursor.getColumnIndex(KeyRings.KEY_RING_DATA);
|
||||
|
||||
byte[] data = cursor.getBlob(keyRingDataCol);
|
||||
if (data != null) {
|
||||
@ -103,27 +58,23 @@ public class ProviderHelper {
|
||||
return keyRing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the actual PGPPublicKeyRing object from the database blob associated with the
|
||||
* maserKeyId
|
||||
*
|
||||
* @param context
|
||||
* @param masterKeyId
|
||||
* @return
|
||||
*/
|
||||
public static PGPPublicKeyRing getPGPPublicKeyRingByMasterKeyId(Context context,
|
||||
long masterKeyId) {
|
||||
Uri queryUri = KeyRings.buildPublicKeyRingsByMasterKeyIdUri(Long.toString(masterKeyId));
|
||||
return (PGPPublicKeyRing) getPGPKeyRing(context, queryUri);
|
||||
}
|
||||
|
||||
public static PGPPublicKeyRing getPGPPublicKeyRing(Context context, long rowId) {
|
||||
Uri queryUri = PublicKeyRings.buildPublicKeyRingsUri(Long.toString(rowId));
|
||||
Cursor cursor = context.getContentResolver()
|
||||
.query(queryUri, new String[] { PublicKeyRings._ID, PublicKeyRings.KEY_RING_DATA },
|
||||
null, null, null);
|
||||
|
||||
PGPPublicKeyRing keyRing = null;
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
int keyRingDataCol = cursor.getColumnIndex(PublicKeyRings.KEY_RING_DATA);
|
||||
|
||||
byte[] data = cursor.getBlob(keyRingDataCol);
|
||||
if (data != null) {
|
||||
keyRing = PGPConversionHelper.BytesToPGPPublicKeyRing(data);
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return keyRing;
|
||||
Uri queryUri = KeyRings.buildPublicKeyRingsUri(Long.toString(rowId));
|
||||
return (PGPPublicKeyRing) getPGPKeyRing(context, queryUri);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,50 +87,13 @@ public class ProviderHelper {
|
||||
*/
|
||||
public static PGPSecretKeyRing getPGPSecretKeyRingByMasterKeyId(Context context,
|
||||
long masterKeyId) {
|
||||
Uri queryUri = SecretKeyRings.buildSecretKeyRingsByMasterKeyIdUri(Long
|
||||
.toString(masterKeyId));
|
||||
Cursor cursor = context.getContentResolver()
|
||||
.query(queryUri, new String[] { SecretKeyRings._ID, SecretKeyRings.KEY_RING_DATA },
|
||||
null, null, null);
|
||||
|
||||
PGPSecretKeyRing keyRing = null;
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
int keyRingDataCol = cursor.getColumnIndex(SecretKeyRings.KEY_RING_DATA);
|
||||
|
||||
byte[] data = cursor.getBlob(keyRingDataCol);
|
||||
if (data != null) {
|
||||
keyRing = PGPConversionHelper.BytesToPGPSecretKeyRing(data);
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return keyRing;
|
||||
Uri queryUri = KeyRings.buildSecretKeyRingsByMasterKeyIdUri(Long.toString(masterKeyId));
|
||||
return (PGPSecretKeyRing) getPGPKeyRing(context, queryUri);
|
||||
}
|
||||
|
||||
public static PGPSecretKeyRing getPGPSecretKeyRing(Context context, long rowId) {
|
||||
Uri queryUri = SecretKeyRings.buildSecretKeyRingsUri(Long.toString(rowId));
|
||||
Cursor cursor = context.getContentResolver()
|
||||
.query(queryUri, new String[] { SecretKeyRings._ID, SecretKeyRings.KEY_RING_DATA },
|
||||
null, null, null);
|
||||
|
||||
PGPSecretKeyRing keyRing = null;
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
int keyRingDataCol = cursor.getColumnIndex(SecretKeyRings.KEY_RING_DATA);
|
||||
|
||||
byte[] data = cursor.getBlob(keyRingDataCol);
|
||||
if (data != null) {
|
||||
keyRing = PGPConversionHelper.BytesToPGPSecretKeyRing(data);
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return keyRing;
|
||||
Uri queryUri = KeyRings.buildSecretKeyRingsUri(Long.toString(rowId));
|
||||
return (PGPSecretKeyRing) getPGPKeyRing(context, queryUri);
|
||||
}
|
||||
|
||||
public static PGPSecretKey getPGPSecretKey(Context context, long keyId) {
|
||||
@ -213,8 +127,7 @@ public class ProviderHelper {
|
||||
long masterKeyId = masterKey.getKeyID();
|
||||
|
||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||
Uri deleteUri = PublicKeyRings.buildPublicKeyRingsByMasterKeyIdUri(Long
|
||||
.toString(masterKeyId));
|
||||
Uri deleteUri = KeyRings.buildPublicKeyRingsByMasterKeyIdUri(Long.toString(masterKeyId));
|
||||
|
||||
try {
|
||||
context.getContentResolver().delete(deleteUri, null, null);
|
||||
@ -223,11 +136,11 @@ public class ProviderHelper {
|
||||
}
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(PublicKeyRings.MASTER_KEY_ID, masterKeyId);
|
||||
values.put(PublicKeyRings.KEY_RING_DATA, keyRing.getEncoded());
|
||||
values.put(KeyRings.MASTER_KEY_ID, masterKeyId);
|
||||
values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded());
|
||||
|
||||
// insert new version of this keyRing
|
||||
Uri uri = PublicKeyRings.buildPublicKeyRingsUri();
|
||||
Uri uri = KeyRings.buildPublicKeyRingsUri();
|
||||
Uri insertedUri = context.getContentResolver().insert(uri, values);
|
||||
long keyRingRowId = Long.valueOf(insertedUri.getLastPathSegment());
|
||||
|
||||
@ -269,8 +182,7 @@ public class ProviderHelper {
|
||||
long masterKeyId = masterKey.getKeyID();
|
||||
|
||||
// delete old version of this keyRing, which also deletes all keys and userIds on cascade
|
||||
Uri deleteUri = SecretKeyRings.buildSecretKeyRingsByMasterKeyIdUri(Long
|
||||
.toString(masterKeyId));
|
||||
Uri deleteUri = KeyRings.buildSecretKeyRingsByMasterKeyIdUri(Long.toString(masterKeyId));
|
||||
|
||||
try {
|
||||
context.getContentResolver().delete(deleteUri, null, null);
|
||||
@ -279,12 +191,12 @@ public class ProviderHelper {
|
||||
}
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SecretKeyRings.MASTER_KEY_ID, masterKeyId);
|
||||
values.put(SecretKeyRings.KEY_RING_DATA, keyRing.getEncoded());
|
||||
values.put(KeyRings.MASTER_KEY_ID, masterKeyId);
|
||||
values.put(KeyRings.KEY_RING_DATA, keyRing.getEncoded());
|
||||
|
||||
// insert new version of this keyRing
|
||||
Uri uri = SecretKeyRings.buildSecretKeyRingsUri();
|
||||
Uri insertedUri = context.getContentResolver().insert(uri, values);
|
||||
Uri uri = KeyRings.buildSecretKeyRingsUri();
|
||||
Uri insertedUri = context.getContentResolver().insert(uri, values);
|
||||
long keyRingRowId = Long.valueOf(insertedUri.getLastPathSegment());
|
||||
|
||||
// save all keys and userIds included in keyRing object in database
|
||||
@ -324,23 +236,23 @@ public class ProviderHelper {
|
||||
private static ContentProviderOperation buildPublicKeyOperations(Context context,
|
||||
long keyRingRowId, PGPPublicKey key, int rank) throws IOException {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(PublicKeys.KEY_ID, key.getKeyID());
|
||||
values.put(PublicKeys.IS_MASTER_KEY, key.isMasterKey());
|
||||
values.put(PublicKeys.ALGORITHM, key.getAlgorithm());
|
||||
values.put(PublicKeys.KEY_SIZE, key.getBitStrength());
|
||||
values.put(PublicKeys.CAN_SIGN, PGPHelper.isSigningKey(key));
|
||||
values.put(PublicKeys.CAN_ENCRYPT, PGPHelper.isEncryptionKey(key));
|
||||
values.put(PublicKeys.IS_REVOKED, key.isRevoked());
|
||||
values.put(PublicKeys.CREATION, PGPHelper.getCreationDate(key).getTime() / 1000);
|
||||
values.put(Keys.KEY_ID, key.getKeyID());
|
||||
values.put(Keys.IS_MASTER_KEY, key.isMasterKey());
|
||||
values.put(Keys.ALGORITHM, key.getAlgorithm());
|
||||
values.put(Keys.KEY_SIZE, key.getBitStrength());
|
||||
values.put(Keys.CAN_SIGN, PGPHelper.isSigningKey(key));
|
||||
values.put(Keys.CAN_ENCRYPT, PGPHelper.isEncryptionKey(key));
|
||||
values.put(Keys.IS_REVOKED, key.isRevoked());
|
||||
values.put(Keys.CREATION, PGPHelper.getCreationDate(key).getTime() / 1000);
|
||||
Date expiryDate = PGPHelper.getExpiryDate(key);
|
||||
if (expiryDate != null) {
|
||||
values.put(PublicKeys.EXPIRY, expiryDate.getTime() / 1000);
|
||||
values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
|
||||
}
|
||||
values.put(PublicKeys.KEY_RING_ROW_ID, keyRingRowId);
|
||||
values.put(PublicKeys.KEY_DATA, key.getEncoded());
|
||||
values.put(PublicKeys.RANK, rank);
|
||||
values.put(Keys.KEY_RING_ROW_ID, keyRingRowId);
|
||||
values.put(Keys.KEY_DATA, key.getEncoded());
|
||||
values.put(Keys.RANK, rank);
|
||||
|
||||
Uri uri = PublicKeys.buildPublicKeysUri(Long.toString(keyRingRowId));
|
||||
Uri uri = Keys.buildPublicKeysUri(Long.toString(keyRingRowId));
|
||||
|
||||
return ContentProviderOperation.newInsert(uri).withValues(values).build();
|
||||
}
|
||||
@ -358,11 +270,11 @@ public class ProviderHelper {
|
||||
private static ContentProviderOperation buildPublicUserIdOperations(Context context,
|
||||
long keyRingRowId, String userId, int rank) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(PublicUserIds.KEY_RING_ROW_ID, keyRingRowId);
|
||||
values.put(PublicUserIds.USER_ID, userId);
|
||||
values.put(PublicUserIds.RANK, rank);
|
||||
values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId);
|
||||
values.put(UserIds.USER_ID, userId);
|
||||
values.put(UserIds.RANK, rank);
|
||||
|
||||
Uri uri = PublicUserIds.buildPublicUserIdsUri(Long.toString(keyRingRowId));
|
||||
Uri uri = UserIds.buildPublicUserIdsUri(Long.toString(keyRingRowId));
|
||||
|
||||
return ContentProviderOperation.newInsert(uri).withValues(values).build();
|
||||
}
|
||||
@ -380,23 +292,23 @@ public class ProviderHelper {
|
||||
private static ContentProviderOperation buildSecretKeyOperations(Context context,
|
||||
long keyRingRowId, PGPSecretKey key, int rank) throws IOException {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SecretKeys.KEY_ID, key.getKeyID());
|
||||
values.put(SecretKeys.IS_MASTER_KEY, key.isMasterKey());
|
||||
values.put(SecretKeys.ALGORITHM, key.getPublicKey().getAlgorithm());
|
||||
values.put(SecretKeys.KEY_SIZE, key.getPublicKey().getBitStrength());
|
||||
values.put(SecretKeys.CAN_SIGN, PGPHelper.isSigningKey(key));
|
||||
values.put(SecretKeys.CAN_ENCRYPT, PGPHelper.isEncryptionKey(key));
|
||||
values.put(SecretKeys.IS_REVOKED, key.getPublicKey().isRevoked());
|
||||
values.put(SecretKeys.CREATION, PGPHelper.getCreationDate(key).getTime() / 1000);
|
||||
values.put(Keys.KEY_ID, key.getKeyID());
|
||||
values.put(Keys.IS_MASTER_KEY, key.isMasterKey());
|
||||
values.put(Keys.ALGORITHM, key.getPublicKey().getAlgorithm());
|
||||
values.put(Keys.KEY_SIZE, key.getPublicKey().getBitStrength());
|
||||
values.put(Keys.CAN_SIGN, PGPHelper.isSigningKey(key));
|
||||
values.put(Keys.CAN_ENCRYPT, PGPHelper.isEncryptionKey(key));
|
||||
values.put(Keys.IS_REVOKED, key.getPublicKey().isRevoked());
|
||||
values.put(Keys.CREATION, PGPHelper.getCreationDate(key).getTime() / 1000);
|
||||
Date expiryDate = PGPHelper.getExpiryDate(key);
|
||||
if (expiryDate != null) {
|
||||
values.put(SecretKeys.EXPIRY, expiryDate.getTime() / 1000);
|
||||
values.put(Keys.EXPIRY, expiryDate.getTime() / 1000);
|
||||
}
|
||||
values.put(SecretKeys.KEY_RING_ROW_ID, keyRingRowId);
|
||||
values.put(SecretKeys.KEY_DATA, key.getEncoded());
|
||||
values.put(SecretKeys.RANK, rank);
|
||||
values.put(Keys.KEY_RING_ROW_ID, keyRingRowId);
|
||||
values.put(Keys.KEY_DATA, key.getEncoded());
|
||||
values.put(Keys.RANK, rank);
|
||||
|
||||
Uri uri = SecretKeys.buildSecretKeysUri(Long.toString(keyRingRowId));
|
||||
Uri uri = Keys.buildSecretKeysUri(Long.toString(keyRingRowId));
|
||||
|
||||
return ContentProviderOperation.newInsert(uri).withValues(values).build();
|
||||
}
|
||||
@ -414,15 +326,43 @@ public class ProviderHelper {
|
||||
private static ContentProviderOperation buildSecretUserIdOperations(Context context,
|
||||
long keyRingRowId, String userId, int rank) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(SecretUserIds.KEY_RING_ROW_ID, keyRingRowId);
|
||||
values.put(SecretUserIds.USER_ID, userId);
|
||||
values.put(SecretUserIds.RANK, rank);
|
||||
values.put(UserIds.KEY_RING_ROW_ID, keyRingRowId);
|
||||
values.put(UserIds.USER_ID, userId);
|
||||
values.put(UserIds.RANK, rank);
|
||||
|
||||
Uri uri = SecretUserIds.buildSecretUserIdsUri(Long.toString(keyRingRowId));
|
||||
Uri uri = UserIds.buildSecretUserIdsUri(Long.toString(keyRingRowId));
|
||||
|
||||
return ContentProviderOperation.newInsert(uri).withValues(values).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Private helper method
|
||||
*
|
||||
* @param context
|
||||
* @param queryUri
|
||||
* @return
|
||||
*/
|
||||
private static Vector<Integer> getKeyRingsRowIds(Context context, Uri queryUri) {
|
||||
Cursor cursor = context.getContentResolver().query(queryUri, new String[] { KeyRings._ID },
|
||||
null, null, null);
|
||||
|
||||
Vector<Integer> keyIds = new Vector<Integer>();
|
||||
if (cursor != null) {
|
||||
int idCol = cursor.getColumnIndex(KeyRings._ID);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
keyIds.add(cursor.getInt(idCol));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return keyIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves ids of all SecretKeyRings
|
||||
*
|
||||
@ -430,25 +370,8 @@ public class ProviderHelper {
|
||||
* @return
|
||||
*/
|
||||
public static Vector<Integer> getSecretKeyRingsRowIds(Context context) {
|
||||
Uri queryUri = SecretKeyRings.buildSecretKeyRingsUri();
|
||||
Cursor cursor = context.getContentResolver().query(queryUri,
|
||||
new String[] { SecretKeyRings._ID }, null, null, null);
|
||||
|
||||
Vector<Integer> keyIds = new Vector<Integer>();
|
||||
if (cursor != null) {
|
||||
int idCol = cursor.getColumnIndex(SecretKeyRings._ID);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
keyIds.add(cursor.getInt(idCol));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return keyIds;
|
||||
Uri queryUri = KeyRings.buildSecretKeyRingsUri();
|
||||
return getKeyRingsRowIds(context, queryUri);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -458,35 +381,18 @@ public class ProviderHelper {
|
||||
* @return
|
||||
*/
|
||||
public static Vector<Integer> getPublicKeyRingsRowIds(Context context) {
|
||||
Uri queryUri = PublicKeyRings.buildPublicKeyRingsUri();
|
||||
Cursor cursor = context.getContentResolver().query(queryUri,
|
||||
new String[] { PublicKeyRings._ID }, null, null, null);
|
||||
|
||||
Vector<Integer> keyIds = new Vector<Integer>();
|
||||
if (cursor != null) {
|
||||
int idCol = cursor.getColumnIndex(PublicKeyRings._ID);
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
keyIds.add(cursor.getInt(idCol));
|
||||
} while (cursor.moveToNext());
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return keyIds;
|
||||
Uri queryUri = KeyRings.buildPublicKeyRingsUri();
|
||||
return getKeyRingsRowIds(context, queryUri);
|
||||
}
|
||||
|
||||
public static void deletePublicKeyRing(Context context, long rowId) {
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
cr.delete(PublicKeyRings.buildPublicKeyRingsUri(Long.toString(rowId)), null, null);
|
||||
cr.delete(KeyRings.buildPublicKeyRingsUri(Long.toString(rowId)), null, null);
|
||||
}
|
||||
|
||||
public static void deleteSecretKeyRing(Context context, long rowId) {
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
cr.delete(SecretKeyRings.buildSecretKeyRingsUri(Long.toString(rowId)), null, null);
|
||||
cr.delete(KeyRings.buildSecretKeyRingsUri(Long.toString(rowId)), null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,10 @@
|
||||
package org.thialfihar.android.apg.ui;
|
||||
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.R.id;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicKeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicKeys;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicUserIds;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.UserIds;
|
||||
import org.thialfihar.android.apg.ui.widget.ExpandableListFragment;
|
||||
import org.thialfihar.android.apg.ui.widget.KeyListAdapter;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.actionbarsherlock.app.SherlockListFragment;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@ -47,7 +40,7 @@ public class KeyListPublicFragment extends ExpandableListFragment implements
|
||||
// We have a menu item to show in action bar.
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
mAdapter = new KeyListAdapter(mActivity, getLoaderManager(), null, Id.type.public_key);
|
||||
mAdapter = new KeyListAdapter(mActivity, null, KeyListAdapter.KEY_TYPE_PUBLIC);
|
||||
setListAdapter(mAdapter);
|
||||
|
||||
// Start out with a progress indicator.
|
||||
@ -59,16 +52,16 @@ public class KeyListPublicFragment extends ExpandableListFragment implements
|
||||
}
|
||||
|
||||
// These are the rows that we will retrieve.
|
||||
static final String[] PROJECTION = new String[] { PublicKeyRings._ID,
|
||||
PublicKeyRings.MASTER_KEY_ID, PublicUserIds.USER_ID };
|
||||
static final String[] PROJECTION = new String[] { KeyRings._ID, KeyRings.MASTER_KEY_ID,
|
||||
UserIds.USER_ID };
|
||||
|
||||
static final String SORT_ORDER = PublicUserIds.USER_ID + " ASC";
|
||||
static final String SORT_ORDER = UserIds.USER_ID + " ASC";
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||
// This is called when a new Loader needs to be created. This
|
||||
// sample only has one Loader, so we don't care about the ID.
|
||||
Uri baseUri = PublicKeyRings.buildPublicKeyRingsUri();
|
||||
Uri baseUri = KeyRings.buildPublicKeyRingsUri();
|
||||
|
||||
// Now create and return a CursorLoader that will take care of
|
||||
// creating a Cursor for the data being displayed.
|
||||
|
@ -1,8 +1,7 @@
|
||||
package org.thialfihar.android.apg.ui;
|
||||
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.SecretKeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.SecretUserIds;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.UserIds;
|
||||
import org.thialfihar.android.apg.ui.widget.ExpandableListFragment;
|
||||
import org.thialfihar.android.apg.ui.widget.KeyListAdapter;
|
||||
|
||||
@ -41,7 +40,7 @@ public class KeyListSecretFragment extends ExpandableListFragment implements
|
||||
// We have a menu item to show in action bar.
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
mAdapter = new KeyListAdapter(mActivity, getLoaderManager(), null, Id.type.secret_key);
|
||||
mAdapter = new KeyListAdapter(mActivity, null, KeyListAdapter.KEY_TYPE_SECRET);
|
||||
setListAdapter(mAdapter);
|
||||
|
||||
// Start out with a progress indicator.
|
||||
@ -53,16 +52,16 @@ public class KeyListSecretFragment extends ExpandableListFragment implements
|
||||
}
|
||||
|
||||
// These are the rows that we will retrieve.
|
||||
static final String[] PROJECTION = new String[] { SecretKeyRings._ID,
|
||||
SecretKeyRings.MASTER_KEY_ID, SecretUserIds.USER_ID };
|
||||
static final String[] PROJECTION = new String[] { KeyRings._ID, KeyRings.MASTER_KEY_ID,
|
||||
UserIds.USER_ID };
|
||||
|
||||
static final String SORT_ORDER = SecretUserIds.USER_ID + " ASC";
|
||||
static final String SORT_ORDER = UserIds.USER_ID + " ASC";
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||
// This is called when a new Loader needs to be created. This
|
||||
// sample only has one Loader, so we don't care about the ID.
|
||||
Uri baseUri = SecretKeyRings.buildSecretKeyRingsUri();
|
||||
Uri baseUri = KeyRings.buildSecretKeyRingsUri();
|
||||
|
||||
// Now create and return a CursorLoader that will take care of
|
||||
// creating a Cursor for the data being displayed.
|
||||
|
@ -2,14 +2,12 @@ package org.thialfihar.android.apg.ui;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicKeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicKeys;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicUserIds;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.KeyRings;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.Keys;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.UserIds;
|
||||
import org.thialfihar.android.apg.ui.widget.SelectPublicKeyCursorAdapter;
|
||||
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import com.actionbarsherlock.app.SherlockListActivity;
|
||||
import com.actionbarsherlock.app.SherlockListFragment;
|
||||
|
||||
import android.database.Cursor;
|
||||
@ -58,7 +56,7 @@ public class SelectPublicKeyListFragment extends SherlockListFragment implements
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
static final String SORT_ORDER = PublicUserIds.USER_ID + " ASC";
|
||||
static final String SORT_ORDER = UserIds.USER_ID + " ASC";
|
||||
|
||||
// static final String SELECTION =
|
||||
|
||||
@ -66,7 +64,7 @@ public class SelectPublicKeyListFragment extends SherlockListFragment implements
|
||||
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
|
||||
// This is called when a new Loader needs to be created. This
|
||||
// sample only has one Loader, so we don't care about the ID.
|
||||
Uri baseUri = PublicKeyRings.buildPublicKeyRingsUri();
|
||||
Uri baseUri = KeyRings.buildPublicKeyRingsUri();
|
||||
|
||||
// Now create and return a CursorLoader that will take care of
|
||||
// creating a Cursor for the data being displayed.
|
||||
@ -74,15 +72,15 @@ public class SelectPublicKeyListFragment extends SherlockListFragment implements
|
||||
// These are the rows that we will retrieve.
|
||||
long now = new Date().getTime() / 1000;
|
||||
String[] projection = new String[] {
|
||||
PublicKeyRings._ID, // 0
|
||||
PublicKeyRings.MASTER_KEY_ID, // 1
|
||||
PublicUserIds.USER_ID, // 2
|
||||
"(SELECT COUNT(" + PublicKeys._ID + ") WHERE " + PublicKeys.IS_REVOKED
|
||||
+ " = '0' AND " + PublicKeys.CAN_ENCRYPT + " = '1')", // 3
|
||||
"(SELECT COUNT(" + PublicKeys._ID + ") WHERE " + PublicKeys.IS_REVOKED
|
||||
+ " = '0' AND " + PublicKeys.CAN_ENCRYPT + " = '1' AND "
|
||||
+ PublicKeys.CREATION + " <= '" + now + "' AND " + "(" + PublicKeys.EXPIRY
|
||||
+ " IS NULL OR " + PublicKeys.EXPIRY + " >= '" + now + "'))", // 4
|
||||
KeyRings._ID, // 0
|
||||
KeyRings.MASTER_KEY_ID, // 1
|
||||
UserIds.USER_ID, // 2
|
||||
"(SELECT COUNT(" + Keys._ID + ") WHERE " + Keys.IS_REVOKED + " = '0' AND "
|
||||
+ Keys.CAN_ENCRYPT + " = '1')", // 3
|
||||
"(SELECT COUNT(" + Keys._ID + ") WHERE " + Keys.IS_REVOKED + " = '0' AND "
|
||||
+ Keys.CAN_ENCRYPT + " = '1' AND " + Keys.CREATION + " <= '" + now
|
||||
+ "' AND " + "(" + Keys.EXPIRY + " IS NULL OR " + Keys.EXPIRY + " >= '"
|
||||
+ now + "'))", // 4
|
||||
};
|
||||
|
||||
return new CursorLoader(getActivity(), baseUri, projection, null, null, SORT_ORDER);
|
||||
|
@ -16,42 +16,44 @@
|
||||
|
||||
package org.thialfihar.android.apg.ui.widget;
|
||||
|
||||
import org.thialfihar.android.apg.Id;
|
||||
import org.thialfihar.android.apg.Constants;
|
||||
import org.thialfihar.android.apg.R;
|
||||
import org.thialfihar.android.apg.helper.OtherHelper;
|
||||
import org.thialfihar.android.apg.helper.PGPHelper;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicKeys;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.PublicUserIds;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.SecretKeys;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.SecretUserIds;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.Keys;
|
||||
import org.thialfihar.android.apg.provider.ApgContract.UserIds;
|
||||
import org.thialfihar.android.apg.util.Log;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.database.MergeCursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.BaseColumns;
|
||||
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.ViewGroup;
|
||||
import android.widget.SimpleCursorTreeAdapter;
|
||||
import android.widget.CursorTreeAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class KeyListAdapter extends SimpleCursorTreeAdapter implements
|
||||
LoaderManager.LoaderCallbacks<Cursor> {
|
||||
public class KeyListAdapter extends CursorTreeAdapter {
|
||||
private Context mContext;
|
||||
private LoaderManager mManager;
|
||||
private LayoutInflater mInflater;
|
||||
|
||||
// Id.type.public_key / Id.type.secret_key
|
||||
protected int mKeyType;
|
||||
|
||||
public KeyListAdapter(Context context, LoaderManager manager, Cursor groupCursor, int keyType) {
|
||||
super(context, groupCursor, -1, null, null, -1, null, null);
|
||||
public static int KEY_TYPE_PUBLIC = 0;
|
||||
public static int KEY_TYPE_SECRET = 1;
|
||||
|
||||
private static final int KEY = 0;
|
||||
private static final int USER_ID = 1;
|
||||
private static final int FINGERPRINT = 2;
|
||||
|
||||
public KeyListAdapter(Context context, Cursor groupCursor, int keyType) {
|
||||
super(groupCursor, context);
|
||||
mContext = context;
|
||||
mManager = manager;
|
||||
mInflater = LayoutInflater.from(context);
|
||||
mKeyType = keyType;
|
||||
}
|
||||
@ -65,16 +67,11 @@ public class KeyListAdapter extends SimpleCursorTreeAdapter implements
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds TextViews from view to results from database group cursor.
|
||||
* Binds TextViews from group view to results from database group cursor.
|
||||
*/
|
||||
@Override
|
||||
protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) {
|
||||
int userIdIndex;
|
||||
if (mKeyType == Id.type.public_key) {
|
||||
userIdIndex = cursor.getColumnIndex(PublicUserIds.USER_ID);
|
||||
} else {
|
||||
userIdIndex = cursor.getColumnIndex(SecretUserIds.USER_ID);
|
||||
}
|
||||
int userIdIndex = cursor.getColumnIndex(UserIds.USER_ID);
|
||||
|
||||
TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId);
|
||||
mainUserId.setText(R.string.unknownUserId);
|
||||
@ -105,131 +102,159 @@ public class KeyListAdapter extends SimpleCursorTreeAdapter implements
|
||||
*/
|
||||
@Override
|
||||
public View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) {
|
||||
|
||||
return mInflater.inflate(R.layout.key_list_child_item_master_key, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) {
|
||||
int keyIdIndex;
|
||||
if (mKeyType == Id.type.public_key) {
|
||||
keyIdIndex = cursor.getColumnIndex(PublicKeys.KEY_ID);
|
||||
// first entry is fingerprint
|
||||
if (cursor.getPosition() == 0) {
|
||||
return mInflater.inflate(R.layout.key_list_child_item_user_id, null);
|
||||
} else {
|
||||
keyIdIndex = cursor.getColumnIndex(SecretKeys.KEY_ID);
|
||||
// differentiate between keys and userIds in MergeCursor
|
||||
if (cursor.getColumnIndex(Keys.KEY_ID) != -1) {
|
||||
// other layout for master key
|
||||
int masterKeyIndex = cursor.getColumnIndex(Keys.IS_MASTER_KEY);
|
||||
if (cursor.getInt(masterKeyIndex) == 1) {
|
||||
return mInflater.inflate(R.layout.key_list_child_item_master_key, null);
|
||||
} else {
|
||||
return mInflater.inflate(R.layout.key_list_child_item_sub_key, null);
|
||||
}
|
||||
} else {
|
||||
return mInflater.inflate(R.layout.key_list_child_item_user_id, null);
|
||||
}
|
||||
}
|
||||
|
||||
TextView keyId = (TextView) view.findViewById(R.id.keyId);
|
||||
String keyIdStr = PGPHelper.getSmallFingerPrint(cursor.getLong(keyIdIndex));
|
||||
keyId.setText(keyIdStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the group, we return a cursor for all the children within that group
|
||||
* Bind TextViews from view of childs to query results
|
||||
*/
|
||||
@Override
|
||||
protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) {
|
||||
// first entry is fingerprint
|
||||
if (cursor.getPosition() == 0) {
|
||||
String fingerprint = PGPHelper.getFingerPrint(context,
|
||||
cursor.getLong(cursor.getColumnIndex(Keys.KEY_ID)));
|
||||
fingerprint = fingerprint.replace(" ", "\n");
|
||||
|
||||
TextView userId = (TextView) view.findViewById(R.id.userId);
|
||||
userId.setText(context.getString(R.string.fingerprint) + ":\n" + fingerprint);
|
||||
} else {
|
||||
// differentiate between keys and userIds in MergeCursor
|
||||
if (cursor.getColumnIndex(Keys.KEY_ID) != -1) {
|
||||
|
||||
String keyIdStr = PGPHelper.getSmallFingerPrint(cursor.getLong(cursor
|
||||
.getColumnIndex(Keys.KEY_ID)));
|
||||
String algorithmStr = PGPHelper.getAlgorithmInfo(
|
||||
cursor.getInt(cursor.getColumnIndex(Keys.ALGORITHM)),
|
||||
cursor.getInt(cursor.getColumnIndex(Keys.KEY_SIZE)));
|
||||
|
||||
TextView keyId = (TextView) view.findViewById(R.id.keyId);
|
||||
keyId.setText(keyIdStr);
|
||||
|
||||
TextView keyDetails = (TextView) view.findViewById(R.id.keyDetails);
|
||||
keyDetails.setText("(" + algorithmStr + ")");
|
||||
|
||||
ImageView encryptIcon = (ImageView) view.findViewById(R.id.ic_encryptKey);
|
||||
if (cursor.getInt(cursor.getColumnIndex(Keys.CAN_ENCRYPT)) != 1) {
|
||||
encryptIcon.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
ImageView signIcon = (ImageView) view.findViewById(R.id.ic_signKey);
|
||||
if (cursor.getInt(cursor.getColumnIndex(Keys.CAN_SIGN)) != 1) {
|
||||
signIcon.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
String userIdStr = cursor.getString(cursor.getColumnIndex(UserIds.USER_ID));
|
||||
|
||||
TextView userId = (TextView) view.findViewById(R.id.userId);
|
||||
userId.setText(userIdStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the group cursor, we start cursors for a fingerprint, keys, and userIds, which are
|
||||
* merged together and form the child cursor
|
||||
*/
|
||||
@Override
|
||||
protected Cursor getChildrenCursor(Cursor groupCursor) {
|
||||
// put keyRingRowId into a bundle to have it when querying child cursors
|
||||
final long idGroup = groupCursor.getLong(groupCursor.getColumnIndex(BaseColumns._ID));
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong("idGroup", idGroup);
|
||||
int groupPos = groupCursor.getPosition();
|
||||
if (mManager.getLoader(groupPos) != null && !mManager.getLoader(groupPos).isReset()) {
|
||||
mManager.restartLoader(groupPos, bundle, this);
|
||||
} else {
|
||||
mManager.initLoader(groupPos, bundle, this);
|
||||
}
|
||||
return null;
|
||||
bundle.putLong("keyRingRowId", idGroup);
|
||||
|
||||
// OLD CODE:
|
||||
// Vector<KeyChild> children = mChildren.get(groupPosition);
|
||||
// if (children != null) {
|
||||
// return children;
|
||||
// }
|
||||
Cursor fingerprintCursor = getChildCursor(bundle, FINGERPRINT);
|
||||
Cursor keyCursor = getChildCursor(bundle, KEY);
|
||||
Cursor userIdCursor = getChildCursor(bundle, USER_ID);
|
||||
|
||||
// mCursor.moveToPosition(groupPosition);
|
||||
// children = new Vector<KeyChild>();
|
||||
// Cursor c = mDatabase.query(Keys.TABLE_NAME, new String[] { Keys._ID, // 0
|
||||
// Keys.KEY_ID, // 1
|
||||
// Keys.IS_MASTER_KEY, // 2
|
||||
// Keys.ALGORITHM, // 3
|
||||
// Keys.KEY_SIZE, // 4
|
||||
// Keys.CAN_SIGN, // 5
|
||||
// Keys.CAN_ENCRYPT, // 6
|
||||
// }, Keys.KEY_RING_ID + " = ?", new String[] { mCursor.getString(0) }, null, null,
|
||||
// Keys.RANK + " ASC");
|
||||
MergeCursor mergeCursor = new MergeCursor(new Cursor[] { fingerprintCursor, keyCursor,
|
||||
userIdCursor });
|
||||
Log.d(Constants.TAG, "mergeCursor:" + DatabaseUtils.dumpCursorToString(mergeCursor));
|
||||
|
||||
// int masterKeyId = -1;
|
||||
// long fingerPrintId = -1;
|
||||
// for (int i = 0; i < c.getCount(); ++i) {
|
||||
// c.moveToPosition(i);
|
||||
// children.add(new KeyChild(c.getLong(1), c.getInt(2) == 1, c.getInt(3), c.getInt(4),
|
||||
// c.getInt(5) == 1, c.getInt(6) == 1));
|
||||
// if (i == 0) {
|
||||
// masterKeyId = c.getInt(0);
|
||||
// fingerPrintId = c.getLong(1);
|
||||
// }
|
||||
// }
|
||||
// c.close();
|
||||
//
|
||||
// if (masterKeyId != -1) {
|
||||
// children.insertElementAt(
|
||||
// new KeyChild(PGPHelper.getFingerPrint(KeyListActivity.this, fingerPrintId),
|
||||
// true), 0);
|
||||
// c = mDatabase.query(UserIds.TABLE_NAME, new String[] { UserIds.USER_ID, // 0
|
||||
// }, UserIds.KEY_ID + " = ? AND " + UserIds.RANK + " > 0", new String[] { ""
|
||||
// + masterKeyId }, null, null, UserIds.RANK + " ASC");
|
||||
//
|
||||
// for (int i = 0; i < c.getCount(); ++i) {
|
||||
// c.moveToPosition(i);
|
||||
// children.add(new KeyChild(c.getString(0)));
|
||||
// }
|
||||
// c.close();
|
||||
// }
|
||||
|
||||
// mChildren.set(groupPosition, children);
|
||||
// return children;
|
||||
return mergeCursor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int groupPos, Bundle bundle) {
|
||||
long idGroup = bundle.getLong("idGroup");
|
||||
/**
|
||||
* This builds a cursor for a specific type of children
|
||||
*
|
||||
* @param bundle
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
private Cursor getChildCursor(Bundle bundle, int type) {
|
||||
long keyRingRowId = bundle.getLong("keyRingRowId");
|
||||
|
||||
Uri uri = null;
|
||||
String[] projection = null;
|
||||
String orderBy = null;
|
||||
if (mKeyType == Id.type.public_key) {
|
||||
projection = new String[] { PublicKeys._ID, // 0
|
||||
PublicKeys.KEY_ID, // 1
|
||||
PublicKeys.IS_MASTER_KEY, // 2
|
||||
PublicKeys.ALGORITHM, // 3
|
||||
PublicKeys.KEY_SIZE, // 4
|
||||
PublicKeys.CAN_SIGN, // 5
|
||||
PublicKeys.CAN_ENCRYPT, // 6
|
||||
};
|
||||
orderBy = PublicKeys.RANK + " ASC";
|
||||
String sortOrder = null;
|
||||
String selection = null;
|
||||
|
||||
switch (type) {
|
||||
case FINGERPRINT:
|
||||
projection = new String[] { Keys._ID, Keys.KEY_ID, Keys.IS_MASTER_KEY, Keys.ALGORITHM,
|
||||
Keys.KEY_SIZE, Keys.CAN_SIGN, Keys.CAN_ENCRYPT, };
|
||||
sortOrder = Keys.RANK + " ASC";
|
||||
|
||||
// use only master key for fingerprint
|
||||
selection = Keys.IS_MASTER_KEY + " = 1 ";
|
||||
|
||||
if (mKeyType == KEY_TYPE_PUBLIC) {
|
||||
uri = Keys.buildPublicKeysUri(String.valueOf(keyRingRowId));
|
||||
} else {
|
||||
uri = Keys.buildSecretKeysUri(String.valueOf(keyRingRowId));
|
||||
}
|
||||
break;
|
||||
|
||||
case KEY:
|
||||
projection = new String[] { Keys._ID, Keys.KEY_ID, Keys.IS_MASTER_KEY, Keys.ALGORITHM,
|
||||
Keys.KEY_SIZE, Keys.CAN_SIGN, Keys.CAN_ENCRYPT, };
|
||||
sortOrder = Keys.RANK + " ASC";
|
||||
|
||||
if (mKeyType == KEY_TYPE_PUBLIC) {
|
||||
uri = Keys.buildPublicKeysUri(String.valueOf(keyRingRowId));
|
||||
} else {
|
||||
uri = Keys.buildSecretKeysUri(String.valueOf(keyRingRowId));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case USER_ID:
|
||||
projection = new String[] { UserIds._ID, UserIds.USER_ID, UserIds.RANK, };
|
||||
sortOrder = UserIds.RANK + " ASC";
|
||||
|
||||
// not the main user id:
|
||||
selection = UserIds.RANK + " > 0 ";
|
||||
|
||||
if (mKeyType == KEY_TYPE_PUBLIC) {
|
||||
uri = UserIds.buildPublicUserIdsUri(String.valueOf(keyRingRowId));
|
||||
} else {
|
||||
uri = UserIds.buildSecretUserIdsUri(String.valueOf(keyRingRowId));
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return null;
|
||||
|
||||
uri = PublicKeys.buildPublicKeysUri(String.valueOf(idGroup));
|
||||
} else {
|
||||
projection = new String[] { SecretKeys._ID, // 0
|
||||
SecretKeys.KEY_ID, // 1
|
||||
SecretKeys.IS_MASTER_KEY, // 2
|
||||
SecretKeys.ALGORITHM, // 3
|
||||
SecretKeys.KEY_SIZE, // 4
|
||||
SecretKeys.CAN_SIGN, // 5
|
||||
SecretKeys.CAN_ENCRYPT, // 6
|
||||
};
|
||||
orderBy = SecretKeys.RANK + " ASC";
|
||||
|
||||
uri = SecretKeys.buildSecretKeysUri(String.valueOf(idGroup));
|
||||
}
|
||||
return new CursorLoader(mContext, uri, projection, null, null, orderBy);
|
||||
|
||||
return mContext.getContentResolver().query(uri, projection, selection, null, sortOrder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
||||
setChildrenCursor(loader.getId(), cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> loader) {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user