change user_id primary key in database, use keyring rather than unified query in consolidate

This commit is contained in:
Vincent Breitmoser 2015-03-11 18:28:36 +01:00
parent 82a2a76a33
commit 9ff4d7b2bc
3 changed files with 26 additions and 14 deletions

View File

@ -109,6 +109,15 @@ public class WrappedUserAttribute implements Serializable {
} }
public byte[][] getSubpackets() {
UserAttributeSubpacket[] subpackets = mVector.toSubpacketArray();
byte[][] ret = new byte[subpackets.length][];
for (int i = 0; i < subpackets.length; i++) {
ret[i] = subpackets[i].getData();
}
return ret;
}
private void readObjectNoData() throws ObjectStreamException { private void readObjectNoData() throws ObjectStreamException {
} }

View File

@ -53,7 +53,7 @@ import java.io.IOException;
*/ */
public class KeychainDatabase extends SQLiteOpenHelper { public class KeychainDatabase extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "openkeychain.db"; private static final String DATABASE_NAME = "openkeychain.db";
private static final int DATABASE_VERSION = 8; private static final int DATABASE_VERSION = 9;
static Boolean apgHack = false; static Boolean apgHack = false;
private Context mContext; private Context mContext;
@ -61,7 +61,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
String KEY_RINGS_PUBLIC = "keyrings_public"; String KEY_RINGS_PUBLIC = "keyrings_public";
String KEY_RINGS_SECRET = "keyrings_secret"; String KEY_RINGS_SECRET = "keyrings_secret";
String KEYS = "keys"; String KEYS = "keys";
String USER_PACKETS = "user_ids"; String USER_PACKETS = "user_packets";
String CERTS = "certs"; String CERTS = "certs";
String API_APPS = "api_apps"; String API_APPS = "api_apps";
String API_ACCOUNTS = "api_accounts"; String API_ACCOUNTS = "api_accounts";
@ -119,8 +119,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
+ UserPacketsColumns.IS_REVOKED + " INTEGER, " + UserPacketsColumns.IS_REVOKED + " INTEGER, "
+ UserPacketsColumns.RANK+ " INTEGER, " + UserPacketsColumns.RANK+ " INTEGER, "
+ "PRIMARY KEY(" + UserPacketsColumns.MASTER_KEY_ID + ", " + UserPacketsColumns.USER_ID + "), " + "PRIMARY KEY(" + UserPacketsColumns.MASTER_KEY_ID + ", " + UserPacketsColumns.RANK + "), "
+ "UNIQUE (" + UserPacketsColumns.MASTER_KEY_ID + ", " + UserPacketsColumns.RANK + "), "
+ "FOREIGN KEY(" + UserPacketsColumns.MASTER_KEY_ID + ") REFERENCES " + "FOREIGN KEY(" + UserPacketsColumns.MASTER_KEY_ID + ") REFERENCES "
+ Tables.KEY_RINGS_PUBLIC + "(" + KeyRingsColumns.MASTER_KEY_ID + ") ON DELETE CASCADE" + Tables.KEY_RINGS_PUBLIC + "(" + KeyRingsColumns.MASTER_KEY_ID + ") ON DELETE CASCADE"
+ ")"; + ")";
@ -267,6 +266,13 @@ public class KeychainDatabase extends SQLiteOpenHelper {
} catch (Exception e) { } catch (Exception e) {
// never mind, the column probably already existed // never mind, the column probably already existed
} }
case 9:
// tbale name for user_ids changed to user_packets
db.execSQL("DROP TABLE IF EXISTS certs");
db.execSQL("DROP TABLE IF EXISTS user_ids");
db.execSQL(CREATE_USER_PACKETS);
db.execSQL(CREATE_CERTS);
} }
// always do consolidate after upgrade // always do consolidate after upgrade

View File

@ -1082,9 +1082,8 @@ public class ProviderHelper {
log.add(LogType.MSG_CON_SAVE_SECRET, indent); log.add(LogType.MSG_CON_SAVE_SECRET, indent);
indent += 1; indent += 1;
final Cursor cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(), new String[]{ final Cursor cursor = mContentResolver.query(KeyRingData.buildSecretKeyRingUri(),
KeyRings.PRIVKEY_DATA, KeyRings.FINGERPRINT, KeyRings.HAS_ANY_SECRET new String[]{ KeyRingData.KEY_RING_DATA }, null, null, null);
}, KeyRings.HAS_ANY_SECRET + " = 1", null, null);
if (cursor == null) { if (cursor == null) {
log.add(LogType.MSG_CON_ERROR_DB, indent); log.add(LogType.MSG_CON_ERROR_DB, indent);
@ -1106,8 +1105,7 @@ public class ProviderHelper {
if (cursor.isAfterLast()) { if (cursor.isAfterLast()) {
return false; return false;
} }
ring = new ParcelableKeyRing(KeyFormattingUtils.convertFingerprintToHex(cursor.getBlob(1)), cursor.getBlob(0) ring = new ParcelableKeyRing(cursor.getBlob(0));
);
cursor.moveToNext(); cursor.moveToNext();
return true; return true;
} }
@ -1144,9 +1142,9 @@ public class ProviderHelper {
log.add(LogType.MSG_CON_SAVE_PUBLIC, indent); log.add(LogType.MSG_CON_SAVE_PUBLIC, indent);
indent += 1; indent += 1;
final Cursor cursor = mContentResolver.query(KeyRings.buildUnifiedKeyRingsUri(), new String[]{ final Cursor cursor = mContentResolver.query(
KeyRings.PUBKEY_DATA, KeyRings.FINGERPRINT KeyRingData.buildPublicKeyRingUri(),
}, null, null, null); new String[]{ KeyRingData.KEY_RING_DATA }, null, null, null);
if (cursor == null) { if (cursor == null) {
log.add(LogType.MSG_CON_ERROR_DB, indent); log.add(LogType.MSG_CON_ERROR_DB, indent);
@ -1168,8 +1166,7 @@ public class ProviderHelper {
if (cursor.isAfterLast()) { if (cursor.isAfterLast()) {
return false; return false;
} }
ring = new ParcelableKeyRing(KeyFormattingUtils.convertFingerprintToHex(cursor.getBlob(1)), cursor.getBlob(0) ring = new ParcelableKeyRing(cursor.getBlob(0));
);
cursor.moveToNext(); cursor.moveToNext();
return true; return true;
} }