save whether key was seen on keyservers
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
@@ -314,7 +314,10 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
||||
+ "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;
|
||||
}
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user