mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-17 21:02:17 -05:00
added some documentation
This commit is contained in:
parent
759009ddb4
commit
d7ef2c1b9e
@ -121,6 +121,7 @@ public class ViewKeyFragment extends LoaderFragment implements
|
|||||||
/**
|
/**
|
||||||
* Checks if a system contact exists for given masterKeyId, and if it does, sets name, picture
|
* Checks if a system contact exists for given masterKeyId, and if it does, sets name, picture
|
||||||
* and onClickListener for the linked system contact's layout
|
* and onClickListener for the linked system contact's layout
|
||||||
|
* In the case of a secret key, "me" contact details are loaded
|
||||||
*
|
*
|
||||||
* @param masterKeyId
|
* @param masterKeyId
|
||||||
*/
|
*/
|
||||||
@ -131,7 +132,7 @@ public class ViewKeyFragment extends LoaderFragment implements
|
|||||||
long contactId;
|
long contactId;
|
||||||
String contactName = null;
|
String contactName = null;
|
||||||
|
|
||||||
if(mIsSecret) {
|
if (mIsSecret) {//all secret keys are linked to "me" profile in contacts
|
||||||
contactId = ContactHelper.getMainProfileContactId(resolver);
|
contactId = ContactHelper.getMainProfileContactId(resolver);
|
||||||
List<String> mainProfileNames = ContactHelper.getMainProfileContactName(context);
|
List<String> mainProfileNames = ContactHelper.getMainProfileContactName(context);
|
||||||
if (mainProfileNames != null) contactName = mainProfileNames.get(0);
|
if (mainProfileNames != null) contactName = mainProfileNames.get(0);
|
||||||
|
@ -214,6 +214,13 @@ public class ContactHelper {
|
|||||||
return new ArrayList<>(names);
|
return new ArrayList<>(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the CONTACT_ID of the main ("me") contact
|
||||||
|
* http://developer.android.com/reference/android/provider/ContactsContract.Profile.html
|
||||||
|
*
|
||||||
|
* @param resolver
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public static long getMainProfileContactId(ContentResolver resolver) {
|
public static long getMainProfileContactId(ContentResolver resolver) {
|
||||||
Cursor profileCursor = resolver.query(
|
Cursor profileCursor = resolver.query(
|
||||||
ContactsContract.Profile.CONTENT_URI,
|
ContactsContract.Profile.CONTENT_URI,
|
||||||
@ -229,6 +236,14 @@ public class ContactHelper {
|
|||||||
return profileCursor.getLong(0);
|
return profileCursor.getLong(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loads the profile picture of the main ("me") contact
|
||||||
|
* http://developer.android.com/reference/android/provider/ContactsContract.Profile.html
|
||||||
|
*
|
||||||
|
* @param contentResolver
|
||||||
|
* @param highRes true for large image if present, false for thumbnail
|
||||||
|
* @return bitmap of loaded photo
|
||||||
|
*/
|
||||||
public static Bitmap loadMainProfilePhoto(ContentResolver contentResolver, boolean highRes) {
|
public static Bitmap loadMainProfilePhoto(ContentResolver contentResolver, boolean highRes) {
|
||||||
try {
|
try {
|
||||||
long mainProfileContactId = getMainProfileContactId(contentResolver);
|
long mainProfileContactId = getMainProfileContactId(contentResolver);
|
||||||
@ -496,6 +511,12 @@ public class ContactHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Links all keys with secrets to the main ("me") contact
|
||||||
|
* http://developer.android.com/reference/android/provider/ContactsContract.Profile.html
|
||||||
|
*
|
||||||
|
* @param context
|
||||||
|
*/
|
||||||
public static void writeKeysToMainProfileContact(Context context) {
|
public static void writeKeysToMainProfileContact(Context context) {
|
||||||
ContentResolver resolver = context.getContentResolver();
|
ContentResolver resolver = context.getContentResolver();
|
||||||
Set<Long> keysToDelete = getMainProfileMasterKeyIds(resolver);
|
Set<Long> keysToDelete = getMainProfileMasterKeyIds(resolver);
|
||||||
@ -509,7 +530,12 @@ public class ContactHelper {
|
|||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
|
long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
|
||||||
|
boolean isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0;
|
||||||
|
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
|
||||||
|
|
||||||
|
if (!isExpired && !isRevoked) {
|
||||||
|
// if expired or revoked will not be removed from keysToDelete or inserted
|
||||||
|
// into main profile ("me" contact)
|
||||||
boolean existsInMainProfile = keysToDelete.remove(masterKeyId);
|
boolean existsInMainProfile = keysToDelete.remove(masterKeyId);
|
||||||
if (!existsInMainProfile) {
|
if (!existsInMainProfile) {
|
||||||
long rawContactId = -1;//new raw contact
|
long rawContactId = -1;//new raw contact
|
||||||
@ -529,6 +555,7 @@ public class ContactHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (long masterKeyId : keysToDelete) {
|
for (long masterKeyId : keysToDelete) {
|
||||||
deleteMainProfileRawContactByMasterKeyId(resolver, masterKeyId);
|
deleteMainProfileRawContactByMasterKeyId(resolver, masterKeyId);
|
||||||
@ -538,6 +565,7 @@ public class ContactHelper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a raw contact into the table defined by ContactsContract.Profile
|
* Inserts a raw contact into the table defined by ContactsContract.Profile
|
||||||
|
* http://developer.android.com/reference/android/provider/ContactsContract.Profile.html
|
||||||
*
|
*
|
||||||
* @param ops
|
* @param ops
|
||||||
* @param masterKeyId
|
* @param masterKeyId
|
||||||
@ -552,7 +580,8 @@ public class ContactHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* deletes a raw contact from the profile table
|
* deletes a raw contact from the main profile table ("me" contact)
|
||||||
|
* http://developer.android.com/reference/android/provider/ContactsContract.Profile.html
|
||||||
*
|
*
|
||||||
* @param resolver
|
* @param resolver
|
||||||
* @param masterKeyId
|
* @param masterKeyId
|
||||||
@ -560,8 +589,8 @@ public class ContactHelper {
|
|||||||
*/
|
*/
|
||||||
private static int deleteMainProfileRawContactByMasterKeyId(ContentResolver resolver,
|
private static int deleteMainProfileRawContactByMasterKeyId(ContentResolver resolver,
|
||||||
long masterKeyId) {
|
long masterKeyId) {
|
||||||
//allows us to actually wipe the RawContact from the device, otherwise would be just flagged
|
// CALLER_IS_SYNCADAPTER allows us to actually wipe the RawContact from the device, otherwise
|
||||||
//for deletion
|
// would be just flagged for deletion
|
||||||
Uri deleteUri = ContactsContract.Profile.CONTENT_RAW_CONTACTS_URI.buildUpon().
|
Uri deleteUri = ContactsContract.Profile.CONTENT_RAW_CONTACTS_URI.buildUpon().
|
||||||
appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
|
appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
|
||||||
|
|
||||||
@ -574,25 +603,47 @@ public class ContactHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete all raw contacts associated to OpenKeychain.
|
* Delete all raw contacts associated to OpenKeychain, including those from "me" contact
|
||||||
|
* defined by ContactsContract.Profile
|
||||||
|
*
|
||||||
|
* @return number of rows deleted
|
||||||
*/
|
*/
|
||||||
private static int debugDeleteRawContacts(ContentResolver resolver) {
|
private static int debugDeleteRawContacts(ContentResolver resolver) {
|
||||||
//allows us to actually wipe the RawContact from the device, otherwise would be just flagged
|
// CALLER_IS_SYNCADAPTER allows us to actually wipe the RawContact from the device, otherwise
|
||||||
//for deletion
|
// would be just flagged for deletion
|
||||||
Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().
|
Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().
|
||||||
appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
|
appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
|
||||||
|
|
||||||
Log.d(Constants.TAG, "Deleting all raw contacts associated to OK...");
|
Log.d(Constants.TAG, "Deleting all raw contacts associated to OK...");
|
||||||
return resolver.delete(deleteUri,
|
int delete = resolver.delete(deleteUri,
|
||||||
ContactsContract.RawContacts.ACCOUNT_TYPE + "=?",
|
ContactsContract.RawContacts.ACCOUNT_TYPE + "=?",
|
||||||
new String[]{
|
new String[]{
|
||||||
Constants.ACCOUNT_TYPE
|
Constants.ACCOUNT_TYPE
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Uri mainProfileDeleteUri = ContactsContract.Profile.CONTENT_RAW_CONTACTS_URI.buildUpon()
|
||||||
|
.appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
|
||||||
|
|
||||||
|
delete += resolver.delete(mainProfileDeleteUri,
|
||||||
|
ContactsContract.RawContacts.ACCOUNT_TYPE + "=?",
|
||||||
|
new String[]{
|
||||||
|
Constants.ACCOUNT_TYPE
|
||||||
|
});
|
||||||
|
|
||||||
|
return delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes raw contacts from ContactsContract.RawContacts based on rawContactId. Does not
|
||||||
|
* delete contacts from the "me" contact defined in ContactsContract.Profile
|
||||||
|
*
|
||||||
|
* @param resolver
|
||||||
|
* @param rawContactId
|
||||||
|
* @return number of rows deleted
|
||||||
|
*/
|
||||||
private static int deleteRawContactById(ContentResolver resolver, long rawContactId) {
|
private static int deleteRawContactById(ContentResolver resolver, long rawContactId) {
|
||||||
//allows us to actually wipe the RawContact from the device, otherwise would be just flagged
|
// CALLER_IS_SYNCADAPTER allows us to actually wipe the RawContact from the device, otherwise
|
||||||
//for deletion
|
// would be just flagged for deletion
|
||||||
Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().
|
Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().
|
||||||
appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
|
appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
|
||||||
|
|
||||||
@ -604,9 +655,17 @@ public class ContactHelper {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes raw contacts from ContactsContract.RawContacts based on masterKeyId. Does not
|
||||||
|
* delete contacts from the "me" contact defined in ContactsContract.Profile
|
||||||
|
*
|
||||||
|
* @param resolver
|
||||||
|
* @param masterKeyId
|
||||||
|
* @return number of rows deleted
|
||||||
|
*/
|
||||||
private static int deleteRawContactByMasterKeyId(ContentResolver resolver, long masterKeyId) {
|
private static int deleteRawContactByMasterKeyId(ContentResolver resolver, long masterKeyId) {
|
||||||
//allows us to actually wipe the RawContact from the device, otherwise would be just flagged
|
// CALLER_IS_SYNCADAPTER allows us to actually wipe the RawContact from the device, otherwise
|
||||||
//for deletion
|
// would be just flagged for deletion
|
||||||
Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().
|
Uri deleteUri = ContactsContract.RawContacts.CONTENT_URI.buildUpon().
|
||||||
appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
|
appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user