save whether key was seen on keyservers

This commit is contained in:
Vincent Breitmoser
2017-05-20 21:37:04 +02:00
parent f7d7adc1ef
commit d75d400453
5 changed files with 35 additions and 16 deletions

View File

@@ -188,6 +188,11 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
log.add(LogType.MSG_IMPORT_FETCH_ERROR_NOT_FOUND, 2);
missingKeys += 1;
byte[] fingerprintHex = entry.getExpectedFingerprint();
if (fingerprintHex != null) {
mKeyWritableRepository.renewKeyLastUpdatedTime(
KeyFormattingUtils.getKeyIdFromFingerprint(fingerprintHex), false);
}
continue;
}
@@ -234,7 +239,7 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
}
if (!skipSave) {
mKeyWritableRepository.renewKeyLastUpdatedTime(key.getMasterKeyId());
mKeyWritableRepository.renewKeyLastUpdatedTime(key.getMasterKeyId(), keyWasDownloaded);
}
}

View File

@@ -1348,11 +1348,16 @@ public class KeyWritableRepository extends KeyRepository {
return ContentProviderOperation.newInsert(uri).withValues(values).build();
}
public Uri renewKeyLastUpdatedTime(long masterKeyId) {
public Uri renewKeyLastUpdatedTime(long masterKeyId, boolean seenOnKeyservers) {
ContentValues values = new ContentValues();
values.put(UpdatedKeys.MASTER_KEY_ID, masterKeyId);
values.put(UpdatedKeys.LAST_UPDATED, GregorianCalendar.getInstance().getTimeInMillis() / 1000);
if (seenOnKeyservers) {
values.put(UpdatedKeys.SEEN_ON_KEYSERVERS, true);
}
// this will actually update/replace, doing the right thing™ for seenOnKeyservers value
// see `KeychainProvider.insert()`
return mContentResolver.insert(UpdatedKeys.CONTENT_URI, values);
}

View File

@@ -55,6 +55,7 @@ public class KeychainContract {
interface UpdatedKeysColumns {
String MASTER_KEY_ID = "master_key_id"; // not a database id
String LAST_UPDATED = "last_updated"; // time since epoch in seconds
String SEEN_ON_KEYSERVERS = "seen_on_keyservers";
}
interface UserPacketsColumns {

View File

@@ -52,7 +52,7 @@ import org.sufficientlysecure.keychain.util.Log;
*/
public class KeychainDatabase extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "openkeychain.db";
private static final int DATABASE_VERSION = 21;
private static final int DATABASE_VERSION = 22;
private Context mContext;
public interface Tables {
@@ -308,13 +308,16 @@ public class KeychainDatabase extends SQLiteOpenHelper {
}
*/
case 20:
db.execSQL(
"CREATE TABLE IF NOT EXISTS overridden_warnings ("
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "identifier TEXT NOT NULL UNIQUE "
+ ")");
db.execSQL(
"CREATE TABLE IF NOT EXISTS overridden_warnings ("
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "identifier TEXT NOT NULL UNIQUE "
+ ")");
if (oldVersion == 18 || oldVersion == 19 || oldVersion == 20) {
case 21:
db.execSQL("ALTER TABLE updated_keys ADD COLUMN seen_on_keyservers INTEGER;");
if (oldVersion == 18 || oldVersion == 19 || oldVersion == 20 || oldVersion == 21) {
// no consolidate for now, often crashes!
return;
}

View File

@@ -639,10 +639,10 @@ public class KeychainProvider extends ContentProvider {
case UPDATED_KEYS_SPECIFIC: {
HashMap<String, String> projectionMap = new HashMap<>();
qb.setTables(Tables.UPDATED_KEYS);
projectionMap.put(UpdatedKeys.MASTER_KEY_ID, Tables.UPDATED_KEYS + "."
+ UpdatedKeys.MASTER_KEY_ID);
projectionMap.put(UpdatedKeys.LAST_UPDATED, Tables.UPDATED_KEYS + "."
+ UpdatedKeys.LAST_UPDATED);
projectionMap.put(UpdatedKeys.MASTER_KEY_ID, Tables.UPDATED_KEYS + "." + UpdatedKeys.MASTER_KEY_ID);
projectionMap.put(UpdatedKeys.LAST_UPDATED, Tables.UPDATED_KEYS + "." + UpdatedKeys.LAST_UPDATED);
projectionMap.put(UpdatedKeys.SEEN_ON_KEYSERVERS,
Tables.UPDATED_KEYS + "." + UpdatedKeys.SEEN_ON_KEYSERVERS);
qb.setProjectionMap(projectionMap);
if (match == UPDATED_KEYS_SPECIFIC) {
qb.appendWhere(UpdatedKeys.MASTER_KEY_ID + " = ");
@@ -780,9 +780,14 @@ public class KeychainProvider extends ContentProvider {
break;
}
case UPDATED_KEYS: {
long updatedKeyId = db.replace(Tables.UPDATED_KEYS, null, values);
rowUri = UpdatedKeys.CONTENT_URI.buildUpon().appendPath("" + updatedKeyId)
.build();
try {
db.insertOrThrow(Tables.UPDATED_KEYS, null, values);
} catch (SQLiteConstraintException e) {
String masterKeyId = values.getAsString(UpdatedKeys.MASTER_KEY_ID);
db.update(Tables.UPDATED_KEYS, values,
UpdatedKeys.MASTER_KEY_ID + " = ?", new String[] { masterKeyId });
}
rowUri = UpdatedKeys.CONTENT_URI;
break;
}
case API_APPS: {