From 1da490f77a14f466d7dd0a9a85fffd812e1faaf1 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 16 May 2020 17:51:14 +0200 Subject: [PATCH] do not request storage permission for attaching location --- .../conversations/ui/ConversationFragment.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index d0e97a9ac..2d9e276af 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -56,6 +56,7 @@ import com.google.common.base.Optional; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; @@ -863,13 +864,13 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } private void commitAttachments() { - if (!hasPermissions(REQUEST_COMMIT_ATTACHMENTS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { + final List attachments = mediaPreviewAdapter.getAttachments(); + if (anyNeedsExternalStoragePermission(attachments) && !hasPermissions(REQUEST_COMMIT_ATTACHMENTS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { return; } if (conversation.getNextEncryption() == Message.ENCRYPTION_AXOLOTL && trustKeysIfNeeded(REQUEST_TRUST_KEYS_ATTACHMENTS)) { return; } - final List attachments = mediaPreviewAdapter.getAttachments(); final PresenceSelector.OnPresenceSelected callback = () -> { for (Iterator i = attachments.iterator(); i.hasNext(); i.remove()) { final Attachment attachment = i.next(); @@ -896,6 +897,16 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } + + private static boolean anyNeedsExternalStoragePermission(final Collection attachments) { + for(final Attachment attachment : attachments) { + if (attachment.getType() != Attachment.Type.LOCATION) { + return true; + } + } + return false; + } + public void toggleInputMethod() { boolean hasAttachments = mediaPreviewAdapter.hasAttachments(); binding.textinput.setVisibility(hasAttachments ? View.GONE : View.VISIBLE);