From cc5db29320f62ccf138aec7de9cb3e98111d0f9d Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 27 Mar 2022 21:06:49 +0200 Subject: [PATCH] Local contact groups insert without permissions --- .../eu/faircode/email/FragmentCompose.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 6b7644e150..b950453450 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1600,8 +1600,7 @@ public class FragmentCompose extends FragmentBase { menu.findItem(R.id.menu_zoom).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_media).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_compact).setEnabled(state == State.LOADED); - menu.findItem(R.id.menu_contact_group).setEnabled( - state == State.LOADED && hasPermission(Manifest.permission.READ_CONTACTS)); + menu.findItem(R.id.menu_contact_group).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_manage_local_contacts).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_answer_insert).setEnabled(state == State.LOADED); menu.findItem(R.id.menu_answer_create).setEnabled(state == State.LOADED); @@ -6776,22 +6775,22 @@ public class FragmentCompose extends FragmentBase { ContactsContract.Groups.ACCOUNT_TYPE, }; - Cursor contacts; - try { - ContentResolver resolver = context.getContentResolver(); - contacts = resolver.query( - ContactsContract.Groups.CONTENT_SUMMARY_URI, - projection, - // ContactsContract.Groups.GROUP_VISIBLE + " = 1" + " AND " + - ContactsContract.Groups.DELETED + " = 0" + - " AND " + ContactsContract.Groups.SUMMARY_COUNT + " > 0", - null, - ContactsContract.Groups.TITLE - ); - } catch (SecurityException ex) { - Log.w(ex); - contacts = new MatrixCursor(projection); - } + Cursor contacts = new MatrixCursor(projection); + if (Helper.hasPermission(context, Manifest.permission.READ_CONTACTS)) + try { + ContentResolver resolver = context.getContentResolver(); + contacts = resolver.query( + ContactsContract.Groups.CONTENT_SUMMARY_URI, + projection, + // ContactsContract.Groups.GROUP_VISIBLE + " = 1" + " AND " + + ContactsContract.Groups.DELETED + " = 0" + + " AND " + ContactsContract.Groups.SUMMARY_COUNT + " > 0", + null, + ContactsContract.Groups.TITLE + ); + } catch (SecurityException ex) { + Log.w(ex); + } DB db = DB.getInstance(context); Cursor local = db.contact().getGroups(