-fixed out of bounds crash when retrieving the main profile name with secret keys

-fixed a possible crash when retrieving the main profile contactid
This commit is contained in:
Daniel Ramos 2015-03-15 00:12:26 +00:00
parent f1b1ecae20
commit d3dd9020f5
2 changed files with 15 additions and 11 deletions

View File

@ -135,7 +135,9 @@ public class ViewKeyFragment extends LoaderFragment implements
if (mIsSecret) {//all secret keys are linked to "me" profile in contacts
contactId = ContactHelper.getMainProfileContactId(resolver);
List<String> mainProfileNames = ContactHelper.getMainProfileContactName(context);
if (mainProfileNames != null) contactName = mainProfileNames.get(0);
if (mainProfileNames != null && mainProfileNames.size() > 0) {
contactName = mainProfileNames.get(0);
}
} else {
contactId = ContactHelper.findContactId(resolver, masterKeyId);

View File

@ -222,18 +222,20 @@ public class ContactHelper {
* @return
*/
public static long getMainProfileContactId(ContentResolver resolver) {
Cursor profileCursor = resolver.query(
ContactsContract.Profile.CONTENT_URI,
new String[]{
ContactsContract.Profile._ID
},
null, null, null);
if (profileCursor == null) {
Cursor profileCursor = resolver.query(ContactsContract.Profile.CONTENT_URI,
new String[]{ ContactsContract.Profile._ID}, null, null, null);
if(profileCursor != null && profileCursor.getCount() != 0 && profileCursor.moveToNext()) {
long contactId = profileCursor.getLong(0);
profileCursor.close();
return contactId;
}
else {
if(profileCursor != null) {
profileCursor.close();
}
return -1;
}
profileCursor.moveToNext();
return profileCursor.getLong(0);
}
/**