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);
|
log.add(LogType.MSG_IMPORT_FETCH_ERROR_NOT_FOUND, 2);
|
||||||
missingKeys += 1;
|
missingKeys += 1;
|
||||||
|
|
||||||
|
byte[] fingerprintHex = entry.getExpectedFingerprint();
|
||||||
|
if (fingerprintHex != null) {
|
||||||
|
mKeyWritableRepository.renewKeyLastUpdatedTime(
|
||||||
|
KeyFormattingUtils.getKeyIdFromFingerprint(fingerprintHex), false);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +239,7 @@ public class ImportOperation extends BaseReadWriteOperation<ImportKeyringParcel>
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!skipSave) {
|
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();
|
return ContentProviderOperation.newInsert(uri).withValues(values).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uri renewKeyLastUpdatedTime(long masterKeyId) {
|
public Uri renewKeyLastUpdatedTime(long masterKeyId, boolean seenOnKeyservers) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(UpdatedKeys.MASTER_KEY_ID, masterKeyId);
|
values.put(UpdatedKeys.MASTER_KEY_ID, masterKeyId);
|
||||||
values.put(UpdatedKeys.LAST_UPDATED, GregorianCalendar.getInstance().getTimeInMillis() / 1000);
|
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);
|
return mContentResolver.insert(UpdatedKeys.CONTENT_URI, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public class KeychainContract {
|
|||||||
interface UpdatedKeysColumns {
|
interface UpdatedKeysColumns {
|
||||||
String MASTER_KEY_ID = "master_key_id"; // not a database id
|
String MASTER_KEY_ID = "master_key_id"; // not a database id
|
||||||
String LAST_UPDATED = "last_updated"; // time since epoch in seconds
|
String LAST_UPDATED = "last_updated"; // time since epoch in seconds
|
||||||
|
String SEEN_ON_KEYSERVERS = "seen_on_keyservers";
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserPacketsColumns {
|
interface UserPacketsColumns {
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ import org.sufficientlysecure.keychain.util.Log;
|
|||||||
*/
|
*/
|
||||||
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 = 21;
|
private static final int DATABASE_VERSION = 22;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
public interface Tables {
|
public interface Tables {
|
||||||
@@ -308,13 +308,16 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
case 20:
|
case 20:
|
||||||
db.execSQL(
|
db.execSQL(
|
||||||
"CREATE TABLE IF NOT EXISTS overridden_warnings ("
|
"CREATE TABLE IF NOT EXISTS overridden_warnings ("
|
||||||
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
|
+ "_id INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||||
+ "identifier TEXT NOT NULL UNIQUE "
|
+ "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!
|
// no consolidate for now, often crashes!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -639,10 +639,10 @@ public class KeychainProvider extends ContentProvider {
|
|||||||
case UPDATED_KEYS_SPECIFIC: {
|
case UPDATED_KEYS_SPECIFIC: {
|
||||||
HashMap<String, String> projectionMap = new HashMap<>();
|
HashMap<String, String> projectionMap = new HashMap<>();
|
||||||
qb.setTables(Tables.UPDATED_KEYS);
|
qb.setTables(Tables.UPDATED_KEYS);
|
||||||
projectionMap.put(UpdatedKeys.MASTER_KEY_ID, Tables.UPDATED_KEYS + "."
|
projectionMap.put(UpdatedKeys.MASTER_KEY_ID, Tables.UPDATED_KEYS + "." + UpdatedKeys.MASTER_KEY_ID);
|
||||||
+ UpdatedKeys.MASTER_KEY_ID);
|
projectionMap.put(UpdatedKeys.LAST_UPDATED, Tables.UPDATED_KEYS + "." + UpdatedKeys.LAST_UPDATED);
|
||||||
projectionMap.put(UpdatedKeys.LAST_UPDATED, Tables.UPDATED_KEYS + "."
|
projectionMap.put(UpdatedKeys.SEEN_ON_KEYSERVERS,
|
||||||
+ UpdatedKeys.LAST_UPDATED);
|
Tables.UPDATED_KEYS + "." + UpdatedKeys.SEEN_ON_KEYSERVERS);
|
||||||
qb.setProjectionMap(projectionMap);
|
qb.setProjectionMap(projectionMap);
|
||||||
if (match == UPDATED_KEYS_SPECIFIC) {
|
if (match == UPDATED_KEYS_SPECIFIC) {
|
||||||
qb.appendWhere(UpdatedKeys.MASTER_KEY_ID + " = ");
|
qb.appendWhere(UpdatedKeys.MASTER_KEY_ID + " = ");
|
||||||
@@ -780,9 +780,14 @@ public class KeychainProvider extends ContentProvider {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case UPDATED_KEYS: {
|
case UPDATED_KEYS: {
|
||||||
long updatedKeyId = db.replace(Tables.UPDATED_KEYS, null, values);
|
try {
|
||||||
rowUri = UpdatedKeys.CONTENT_URI.buildUpon().appendPath("" + updatedKeyId)
|
db.insertOrThrow(Tables.UPDATED_KEYS, null, values);
|
||||||
.build();
|
} 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;
|
break;
|
||||||
}
|
}
|
||||||
case API_APPS: {
|
case API_APPS: {
|
||||||
|
|||||||
Reference in New Issue
Block a user