aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2015-03-15 15:34:07 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2015-03-15 15:34:07 +0100
commitf1dc58ddfd6a26fa6670f0adeec515ac668194f6 (patch)
treefd213a6aa078db9cb88361fb8c40a6ebc44f0dd5 /OpenKeychain/src
parentf4cb254404fd1194dda2995fa1ddab85ea0a28d3 (diff)
parentd3dd9020f585b8f587d9f2deb377750dbd260db1 (diff)
downloadopen-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.java4
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ContactHelper.java22
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);
}
/**