use WorkManager for key sync
This commit is contained in:
@@ -41,6 +41,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeys;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
@@ -284,7 +285,7 @@ public class KeyRepository {
|
||||
Cursor lastUpdatedCursor = contentResolver.query(
|
||||
UpdatedKeys.CONTENT_URI,
|
||||
new String[] { UpdatedKeys.LAST_UPDATED },
|
||||
UpdatedKeys.MASTER_KEY_ID + " = ?",
|
||||
Tables.UPDATED_KEYS + "." + UpdatedKeys.MASTER_KEY_ID + " = ?",
|
||||
new String[] { "" + masterKeyId },
|
||||
null
|
||||
);
|
||||
|
||||
@@ -55,6 +55,7 @@ public class KeychainContract {
|
||||
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";
|
||||
String FINGERPRINT = "fingerprint";
|
||||
}
|
||||
|
||||
interface KeySignaturesColumns {
|
||||
|
||||
@@ -788,14 +788,23 @@ public class KeychainProvider extends ContentProvider implements SimpleContentRe
|
||||
case UPDATED_KEYS:
|
||||
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 + " AS " + UpdatedKeys.MASTER_KEY_ID);
|
||||
projectionMap.put(UpdatedKeys.LAST_UPDATED,
|
||||
Tables.UPDATED_KEYS + "." + UpdatedKeys.LAST_UPDATED + " AS " + UpdatedKeys.LAST_UPDATED);
|
||||
projectionMap.put(UpdatedKeys.SEEN_ON_KEYSERVERS,
|
||||
Tables.UPDATED_KEYS + "." + UpdatedKeys.SEEN_ON_KEYSERVERS);
|
||||
Tables.UPDATED_KEYS + "." + UpdatedKeys.SEEN_ON_KEYSERVERS + " AS " + UpdatedKeys.SEEN_ON_KEYSERVERS);
|
||||
projectionMap.put(UpdatedKeys.FINGERPRINT,
|
||||
Tables.KEYS + "." + Keys.FINGERPRINT + " AS " + UpdatedKeys.FINGERPRINT);
|
||||
qb.setProjectionMap(projectionMap);
|
||||
|
||||
qb.setTables(Tables.UPDATED_KEYS +
|
||||
" LEFT JOIN " + Tables.KEYS +
|
||||
" ON (" + Tables.KEYS + "." + Keys.KEY_ID + " = " + Tables.UPDATED_KEYS + "." + UpdatedKeys.MASTER_KEY_ID + ")"
|
||||
);
|
||||
|
||||
if (match == UPDATED_KEYS_SPECIFIC) {
|
||||
qb.appendWhere(UpdatedKeys.MASTER_KEY_ID + " = ");
|
||||
qb.appendWhere(Tables.UPDATED_KEYS + "." + UpdatedKeys.MASTER_KEY_ID + " = ");
|
||||
qb.appendWhereEscapeString(uri.getPathSegments().get(1));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package org.sufficientlysecure.keychain.provider;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
@@ -11,6 +14,7 @@ import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.UpdatedKeys;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
||||
|
||||
|
||||
public class LastUpdateInteractor {
|
||||
@@ -32,7 +36,7 @@ public class LastUpdateInteractor {
|
||||
Cursor cursor = contentResolver.query(
|
||||
UpdatedKeys.CONTENT_URI,
|
||||
new String[] { UpdatedKeys.SEEN_ON_KEYSERVERS },
|
||||
UpdatedKeys.MASTER_KEY_ID + " = ?",
|
||||
Tables.UPDATED_KEYS + "." + UpdatedKeys.MASTER_KEY_ID + " = ?",
|
||||
new String[] { "" + masterKeyId },
|
||||
null
|
||||
);
|
||||
@@ -75,4 +79,27 @@ public class LastUpdateInteractor {
|
||||
databaseNotifyManager.notifyKeyserverStatusChange(masterKeyId);
|
||||
return insert;
|
||||
}
|
||||
|
||||
public List<byte[]> getFingerprintsForKeysOlderThan(long olderThan, TimeUnit timeUnit) {
|
||||
Cursor outdatedKeysCursor = contentResolver.query(
|
||||
KeychainContract.UpdatedKeys.CONTENT_URI,
|
||||
new String[] { KeychainContract.UpdatedKeys.FINGERPRINT, },
|
||||
KeychainContract.UpdatedKeys.LAST_UPDATED + " < ?",
|
||||
new String[] { Long.toString(timeUnit.toSeconds(olderThan)) },
|
||||
null
|
||||
);
|
||||
|
||||
List<byte[]> fingerprintList = new ArrayList<>();
|
||||
if (outdatedKeysCursor == null) {
|
||||
return fingerprintList;
|
||||
}
|
||||
|
||||
while (outdatedKeysCursor.moveToNext()) {
|
||||
byte[] fingerprint = outdatedKeysCursor.getBlob(0);
|
||||
fingerprintList.add(fingerprint);
|
||||
}
|
||||
outdatedKeysCursor.close();
|
||||
|
||||
return fingerprintList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user