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