Add database columns for crypto consumer preferences

This commit is contained in:
Dominik Schürmann 2013-06-18 01:48:25 +02:00
parent d4e054d5f2
commit 36cc814e84
3 changed files with 33 additions and 2 deletions

View File

@ -43,7 +43,7 @@ public class KeychainContract {
String CREATION = "creation";
String EXPIRY = "expiry";
String KEY_RING_ROW_ID = "key_ring_row_id"; // foreign key to key_rings._ID
String KEY_DATA = "key_data"; // PGPPublicKey / PGPSecretKey blob
String KEY_DATA = "key_data"; // PGPPublicKey/PGPSecretKey blob
String RANK = "rank";
}
@ -55,6 +55,11 @@ public class KeychainContract {
interface CryptoConsumersColumns {
String PACKAGE_NAME = "package_name";
String PRIVATE_KEY_ID = "private_key_id"; // not a database id
String ASCII_ARMOR = "ascii_armor";
String ENCRYPTION_ALGORITHM = "encryption_algorithm";
String HASH_ALORITHM = "hash_algorithm";
String COMPRESSION = "compression";
}
public static final class KeyTypes {
@ -83,6 +88,7 @@ public class KeychainContract {
public static final String PATH_KEYS = "keys";
public static final String BASE_CRYPTO_CONSUMERS = "crypto_consumers";
public static final String PATH_BY_PACKAGE_NAME = "package_name";
public static class KeyRings implements KeyRingsColumns, BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
@ -226,6 +232,11 @@ public class KeychainContract {
public static Uri buildIdUri(String rowId) {
return CONTENT_URI.buildUpon().appendPath(rowId).build();
}
public static Uri buildByPackageNameUri(String packageName) {
return CONTENT_URI.buildUpon().appendPath(PATH_BY_PACKAGE_NAME).appendPath(packageName)
.build();
}
}
public static class DataStream {

View File

@ -67,7 +67,11 @@ public class KeychainDatabase extends SQLiteOpenHelper {
private static final String CREATE_CRYPTO_CONSUMERS = "CREATE TABLE IF NOT EXISTS "
+ Tables.CRYPTO_CONSUMERS + " (" + BaseColumns._ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + CryptoConsumersColumns.PACKAGE_NAME
+ " TEXT UNIQUE)";
+ " TEXT UNIQUE, " + CryptoConsumersColumns.PRIVATE_KEY_ID + " INT64, "
+ CryptoConsumersColumns.ASCII_ARMOR + " INTEGER, "
+ CryptoConsumersColumns.ENCRYPTION_ALGORITHM + " INTEGER, "
+ CryptoConsumersColumns.HASH_ALORITHM + " INTEGER, "
+ CryptoConsumersColumns.COMPRESSION + " INTEGER)";
KeychainDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);

View File

@ -80,6 +80,7 @@ public class KeychainProvider extends ContentProvider {
private static final int CRYPTO_CONSUMERS = 301;
private static final int CRYPTO_CONSUMERS_BY_ROW_ID = 302;
private static final int CRYPTO_CONSUMERS_BY_PACKAGE_NAME = 303;
// private static final int DATA_STREAM = 401;
@ -230,6 +231,8 @@ public class KeychainProvider extends ContentProvider {
matcher.addURI(authority, KeychainContract.BASE_CRYPTO_CONSUMERS, CRYPTO_CONSUMERS);
matcher.addURI(authority, KeychainContract.BASE_CRYPTO_CONSUMERS + "/#",
CRYPTO_CONSUMERS_BY_ROW_ID);
matcher.addURI(authority, KeychainContract.BASE_CRYPTO_CONSUMERS + "/"
+ KeychainContract.PATH_BY_PACKAGE_NAME + "/*", CRYPTO_CONSUMERS_BY_PACKAGE_NAME);
/**
* data stream
@ -294,6 +297,7 @@ public class KeychainProvider extends ContentProvider {
return CryptoConsumers.CONTENT_TYPE;
case CRYPTO_CONSUMERS_BY_ROW_ID:
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
return CryptoConsumers.CONTENT_ITEM_TYPE;
default:
@ -607,6 +611,12 @@ public class KeychainProvider extends ContentProvider {
case CRYPTO_CONSUMERS:
qb.setTables(Tables.CRYPTO_CONSUMERS);
break;
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
qb.setTables(Tables.CRYPTO_CONSUMERS);
qb.appendWhere(CryptoConsumers.PACKAGE_NAME + " = ");
qb.appendWhereEscapeString(uri.getPathSegments().get(2));
break;
default:
@ -755,6 +765,7 @@ public class KeychainProvider extends ContentProvider {
selectionArgs);
break;
case CRYPTO_CONSUMERS_BY_ROW_ID:
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
count = db.delete(Tables.CRYPTO_CONSUMERS,
buildDefaultCryptoConsumersSelection(uri, selection), selectionArgs);
break;
@ -818,6 +829,11 @@ public class KeychainProvider extends ContentProvider {
count = db.update(Tables.USER_IDS, values,
buildDefaultUserIdsSelection(uri, selection), selectionArgs);
break;
case CRYPTO_CONSUMERS_BY_ROW_ID:
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
count = db.update(Tables.CRYPTO_CONSUMERS, values,
buildDefaultCryptoConsumersSelection(uri, selection), selectionArgs);
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}