mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-02 13:32:19 -05:00
Use index constants in ContactHelper
This commit is contained in:
parent
0557e0680e
commit
69865a6d57
@ -57,10 +57,20 @@ public class ContactHelper {
|
|||||||
KeychainContract.KeyRings.MASTER_KEY_ID,
|
KeychainContract.KeyRings.MASTER_KEY_ID,
|
||||||
KeychainContract.KeyRings.EXPIRY,
|
KeychainContract.KeyRings.EXPIRY,
|
||||||
KeychainContract.KeyRings.IS_REVOKED};
|
KeychainContract.KeyRings.IS_REVOKED};
|
||||||
|
|
||||||
|
public static final int INDEX_USER_ID = 0;
|
||||||
|
public static final int INDEX_FINGERPRINT = 1;
|
||||||
|
public static final int INDEX_KEY_ID = 2;
|
||||||
|
public static final int INDEX_MASTER_KEY_ID = 3;
|
||||||
|
public static final int INDEX_EXPIRY = 4;
|
||||||
|
public static final int INDEX_IS_REVOKED = 5;
|
||||||
|
|
||||||
public static final String[] USER_IDS_PROJECTION = new String[]{
|
public static final String[] USER_IDS_PROJECTION = new String[]{
|
||||||
UserPackets.USER_ID
|
UserPackets.USER_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static final int INDEX_USER_IDS_USER_ID = 0;
|
||||||
|
|
||||||
public static final String NON_REVOKED_SELECTION = UserPackets.IS_REVOKED + "=0";
|
public static final String NON_REVOKED_SELECTION = UserPackets.IS_REVOKED + "=0";
|
||||||
|
|
||||||
public static final String[] ID_PROJECTION = new String[]{ContactsContract.RawContacts._ID};
|
public static final String[] ID_PROJECTION = new String[]{ContactsContract.RawContacts._ID};
|
||||||
@ -301,23 +311,26 @@ public class ContactHelper {
|
|||||||
null, null, null);
|
null, null, null);
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
String[] primaryUserId = KeyRing.splitUserId(cursor.getString(0));
|
String[] primaryUserId = KeyRing.splitUserId(cursor.getString(INDEX_USER_ID));
|
||||||
String fingerprint = KeyFormattingUtils.convertFingerprintToHex(cursor.getBlob(1));
|
String fingerprint = KeyFormattingUtils.convertFingerprintToHex(cursor.getBlob(INDEX_FINGERPRINT));
|
||||||
contactFingerprints.remove(fingerprint);
|
contactFingerprints.remove(fingerprint);
|
||||||
String keyIdShort = KeyFormattingUtils.convertKeyIdToHexShort(cursor.getLong(2));
|
String keyIdShort = KeyFormattingUtils.convertKeyIdToHexShort(cursor.getLong(INDEX_KEY_ID));
|
||||||
long masterKeyId = cursor.getLong(3);
|
long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
|
||||||
boolean isExpired = !cursor.isNull(4) && new Date(cursor.getLong(4) * 1000).before(new Date());
|
boolean isExpired = !cursor.isNull(INDEX_EXPIRY)
|
||||||
boolean isRevoked = cursor.getInt(5) > 0;
|
&& new Date(cursor.getLong(INDEX_EXPIRY) * 1000).before(new Date());
|
||||||
|
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
|
||||||
int rawContactId = findRawContactId(resolver, fingerprint);
|
int rawContactId = findRawContactId(resolver, fingerprint);
|
||||||
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
|
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
|
||||||
|
|
||||||
|
Log.d(Constants.TAG, "raw contact id: "+rawContactId);
|
||||||
|
|
||||||
// Do not store expired or revoked keys in contact db - and remove them if they already exist
|
// Do not store expired or revoked keys in contact db - and remove them if they already exist
|
||||||
if (isExpired || isRevoked) {
|
if (isExpired || isRevoked) {
|
||||||
if (rawContactId != -1) {
|
if (rawContactId != -1) {
|
||||||
resolver.delete(ContactsContract.RawContacts.CONTENT_URI, ID_SELECTION,
|
resolver.delete(ContactsContract.RawContacts.CONTENT_URI, ID_SELECTION,
|
||||||
new String[]{Integer.toString(rawContactId)});
|
new String[]{Integer.toString(rawContactId)});
|
||||||
}
|
}
|
||||||
} else {
|
} else if (primaryUserId[0] != null) {
|
||||||
|
|
||||||
// Create a new rawcontact with corresponding key if it does not exist yet
|
// Create a new rawcontact with corresponding key if it does not exist yet
|
||||||
if (rawContactId == -1) {
|
if (rawContactId == -1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user