fix date queries in autocrypt handling
This commit is contained in:
@@ -36,6 +36,11 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAutocryptPee
|
|||||||
public class AutocryptPeerDataAccessObject {
|
public class AutocryptPeerDataAccessObject {
|
||||||
private static final long AUTOCRYPT_DISCOURAGE_THRESHOLD_MILLIS = 35 * DateUtils.DAY_IN_MILLIS;
|
private static final long AUTOCRYPT_DISCOURAGE_THRESHOLD_MILLIS = 35 * DateUtils.DAY_IN_MILLIS;
|
||||||
|
|
||||||
|
private static final String[] PROJECTION_LAST_SEEN = { ApiAutocryptPeer.LAST_SEEN };
|
||||||
|
private static final String[] PROJECTION_LAST_SEEN_KEY = { ApiAutocryptPeer.LAST_SEEN_KEY };
|
||||||
|
private static final String[] PROJECTION_GOSSIP_LAST_SEEN_KEY = { ApiAutocryptPeer.GOSSIP_LAST_SEEN_KEY };
|
||||||
|
private static final String[] PROJECTION_MASTER_KEY_ID = { ApiAutocryptPeer.MASTER_KEY_ID };
|
||||||
|
|
||||||
private static final String[] PROJECTION_AUTOCRYPT_QUERY = {
|
private static final String[] PROJECTION_AUTOCRYPT_QUERY = {
|
||||||
ApiAutocryptPeer.IDENTIFIER,
|
ApiAutocryptPeer.IDENTIFIER,
|
||||||
ApiAutocryptPeer.LAST_SEEN,
|
ApiAutocryptPeer.LAST_SEEN,
|
||||||
@@ -104,12 +109,12 @@ public class AutocryptPeerDataAccessObject {
|
|||||||
|
|
||||||
public Long getMasterKeyIdForAutocryptPeer(String autocryptId) {
|
public Long getMasterKeyIdForAutocryptPeer(String autocryptId) {
|
||||||
Cursor cursor = queryInterface.query(
|
Cursor cursor = queryInterface.query(
|
||||||
ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId), null, null, null, null);
|
ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId),
|
||||||
|
PROJECTION_MASTER_KEY_ID, null, null, null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
int masterKeyIdColumn = cursor.getColumnIndex(ApiAutocryptPeer.MASTER_KEY_ID);
|
return cursor.getLong(0);
|
||||||
return cursor.getLong(masterKeyIdColumn);
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
@@ -122,11 +127,11 @@ public class AutocryptPeerDataAccessObject {
|
|||||||
|
|
||||||
public Date getLastSeen(String autocryptId) {
|
public Date getLastSeen(String autocryptId) {
|
||||||
Cursor cursor = queryInterface.query(ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId),
|
Cursor cursor = queryInterface.query(ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId),
|
||||||
null, null, null, null);
|
PROJECTION_LAST_SEEN, null, null, null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
long lastUpdated = cursor.getColumnIndex(ApiAutocryptPeer.LAST_SEEN);
|
long lastUpdated = cursor.getLong(0);
|
||||||
return new Date(lastUpdated);
|
return new Date(lastUpdated);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -139,11 +144,11 @@ public class AutocryptPeerDataAccessObject {
|
|||||||
|
|
||||||
public Date getLastSeenKey(String autocryptId) {
|
public Date getLastSeenKey(String autocryptId) {
|
||||||
Cursor cursor = queryInterface.query(ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId),
|
Cursor cursor = queryInterface.query(ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId),
|
||||||
null, null, null, null);
|
PROJECTION_LAST_SEEN_KEY, null, null, null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
long lastUpdated = cursor.getColumnIndex(ApiAutocryptPeer.LAST_SEEN_KEY);
|
long lastUpdated = cursor.getLong(0);
|
||||||
return new Date(lastUpdated);
|
return new Date(lastUpdated);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -156,11 +161,11 @@ public class AutocryptPeerDataAccessObject {
|
|||||||
|
|
||||||
public Date getLastSeenGossip(String autocryptId) {
|
public Date getLastSeenGossip(String autocryptId) {
|
||||||
Cursor cursor = queryInterface.query(ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId),
|
Cursor cursor = queryInterface.query(ApiAutocryptPeer.buildByPackageNameAndAutocryptId(packageName, autocryptId),
|
||||||
null, null, null, null);
|
PROJECTION_GOSSIP_LAST_SEEN_KEY, null, null, null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
long lastUpdated = cursor.getColumnIndex(ApiAutocryptPeer.GOSSIP_LAST_SEEN_KEY);
|
long lastUpdated = cursor.getLong(0);
|
||||||
return new Date(lastUpdated);
|
return new Date(lastUpdated);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -40,13 +40,13 @@ class AutocryptInteractor {
|
|||||||
|
|
||||||
// 1. If the message’s effective date is older than the peers[from-addr].autocrypt_timestamp value, then no changes are required, and the update process terminates.
|
// 1. If the message’s effective date is older than the peers[from-addr].autocrypt_timestamp value, then no changes are required, and the update process terminates.
|
||||||
Date lastSeenAutocrypt = autocryptPeerDao.getLastSeenKey(autocryptPeerId);
|
Date lastSeenAutocrypt = autocryptPeerDao.getLastSeenKey(autocryptPeerId);
|
||||||
if (lastSeenAutocrypt != null && lastSeenAutocrypt.after(effectiveDate)) {
|
if (lastSeenAutocrypt != null && effectiveDate.compareTo(lastSeenAutocrypt) <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. If the message’s effective date is more recent than peers[from-addr].last_seen then set peers[from-addr].last_seen to the message’s effective date.
|
// 2. If the message’s effective date is more recent than peers[from-addr].last_seen then set peers[from-addr].last_seen to the message’s effective date.
|
||||||
Date lastSeen = autocryptPeerDao.getLastSeen(autocryptPeerId);
|
Date lastSeen = autocryptPeerDao.getLastSeen(autocryptPeerId);
|
||||||
if (lastSeen == null || lastSeen.after(effectiveDate)) {
|
if (lastSeen == null || effectiveDate.after(lastSeen)) {
|
||||||
autocryptPeerDao.updateLastSeen(autocryptPeerId, effectiveDate);
|
autocryptPeerDao.updateLastSeen(autocryptPeerId, effectiveDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user