From 676ac32a972c736c3a156ca19e224c3ddc2370bc Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 23 Jan 2018 22:02:28 +0100 Subject: [PATCH] delegate uri permission to service when processing files --- .../conversations/services/XmppConnectionService.java | 6 ++++++ .../eu/siacs/conversations/ui/ConversationActivity.java | 2 ++ .../eu/siacs/conversations/ui/ConversationFragment.java | 2 +- .../java/eu/siacs/conversations/ui/ShareWithActivity.java | 6 +++++- src/main/java/eu/siacs/conversations/ui/XmppActivity.java | 8 ++++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 293c71cf5..adececfaf 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -670,6 +670,12 @@ public class XmppConnectionService extends Service { Log.d(Config.LOGTAG, "gcm push message arrived in service. extras=" + intent.getExtras()); pushedAccountHash = intent.getStringExtra("account"); break; + case Intent.ACTION_SEND: + Uri uri = intent.getData(); + if (uri != null) { + Log.d(Config.LOGTAG, "received uri permission for "+uri.toString()); + } + return START_STICKY; } } synchronized (this) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index efa641aa8..34947965a 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -1601,6 +1601,7 @@ public class ConversationActivity extends XmppActivity } final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_file), Toast.LENGTH_LONG); prepareFileToast.show(); + delegateUriPermissionsToService(uri); xmppConnectionService.attachFileToConversation(conversation, uri, new UiInformableCallback() { @Override public void inform(final String text) { @@ -1654,6 +1655,7 @@ public class ConversationActivity extends XmppActivity } final Toast prepareFileToast = Toast.makeText(getApplicationContext(),getText(R.string.preparing_image), Toast.LENGTH_LONG); prepareFileToast.show(); + delegateUriPermissionsToService(uri); xmppConnectionService.attachImageToConversation(conversation, uri, new UiCallback() { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 969281c9a..944fdeee3 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -816,7 +816,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa Toast.makeText(activity, activity.getString(R.string.no_permission_to_access_x, file.getAbsolutePath()), Toast.LENGTH_SHORT).show(); return; } - shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); String mime = message.getMimeType(); if (mime == null) { mime = "*/*"; diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java index 54eaa7ea4..de6fbd23f 100644 --- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java @@ -318,11 +318,15 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer share.multiple = share.uris.size() > 1; replaceToast(getString(share.multiple ? R.string.preparing_images : R.string.preparing_image)); for (Iterator i = share.uris.iterator(); i.hasNext(); i.remove()) { + final Uri uri = i.next(); + delegateUriPermissionsToService(uri); xmppConnectionService.attachImageToConversation(conversation, i.next(), attachFileCallback); } } else { replaceToast(getString(R.string.preparing_file)); - xmppConnectionService.attachFileToConversation(conversation, share.uris.get(0), attachFileCallback); + final Uri uri = share.uris.get(0); + delegateUriPermissionsToService(uri); + xmppConnectionService.attachFileToConversation(conversation, uri, attachFileCallback); } }; if (account.httpUploadAvailable() diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 6c9f02fdc..f3e067b88 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -525,6 +525,14 @@ public abstract class XmppActivity extends Activity { startActivity(intent); } + protected void delegateUriPermissionsToService(Uri uri) { + Intent intent = new Intent(this,XmppConnectionService.class); + intent.setAction(Intent.ACTION_SEND); + intent.setData(uri); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + startService(intent); + } + protected void inviteToConversation(Conversation conversation) { Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class);