diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-03-15 15:34:07 +0100 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2015-03-15 15:34:07 +0100 |
commit | f1dc58ddfd6a26fa6670f0adeec515ac668194f6 (patch) | |
tree | fd213a6aa078db9cb88361fb8c40a6ebc44f0dd5 /OpenKeychain/src | |
parent | f4cb254404fd1194dda2995fa1ddab85ea0a28d3 (diff) | |
parent | d3dd9020f585b8f587d9f2deb377750dbd260db1 (diff) | |
download | open-keychain-f1dc58ddfd6a26fa6670f0adeec515ac668194f6.tar.gz open-keychain-f1dc58ddfd6a26fa6670f0adeec515ac668194f6.tar.bz2 open-keychain-f1dc58ddfd6a26fa6670f0adeec515ac668194f6.zip |
Merge pull request #1147 from Hiperzone/development
-fixed out of bounds crash when retrieving the main profile name with se...
Diffstat (limited to 'OpenKeychain/src')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java | 4 | ||||
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java | 22 |
2 files changed, 15 insertions, 11 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java index 18f1ef8a7..c3a8d60f8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyFragment.java @@ -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); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java index d102745b6..6efc0a5ea 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java @@ -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); } /** |