diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-01-27 21:53:22 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-01-27 21:53:22 +0100 |
commit | f4f11f10b96ab15739522d02097904f686eaf02e (patch) | |
tree | ac0ec85272a2e7ce7013c0dae8c69eb154d1ac65 /src/main | |
parent | 9ebf37726c9b4da1e48ada56ab48137c66ea68b6 (diff) |
delegate uri permission to service when processing files
Diffstat (limited to 'src/main')
5 files changed, 23 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index f3d93cbc0..6378fcb03 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -674,6 +674,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/de/pixart/messenger/ui/ConversationActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java index 005bc2b74..b53c56390 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationActivity.java @@ -1790,6 +1790,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<Message>() { @Override public void inform(final String text) { @@ -1839,6 +1840,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<Message>() { @@ -1872,6 +1874,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<Message>() { diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 00e2f6b12..56ad55b8a 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -858,7 +858,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/de/pixart/messenger/ui/ShareWithActivity.java b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java index 731639280..18afea15d 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java @@ -346,12 +346,16 @@ 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<Uri> i = share.uris.iterator(); i.hasNext(); i.remove()) { + final Uri uri = i.next(); + delegateUriPermissionsToService(uri); ShareWithActivity.this.xmppConnectionService.attachImageToConversation(conversation, i.next(), attachFileCallback); } } else { Log.d(Config.LOGTAG, "ShareWithActivity share() file " + share.uris.size() + " uri(s) " + share.uris.toString()); replaceToast(getString(R.string.preparing_file)); - ShareWithActivity.this.xmppConnectionService.attachFileToConversation(conversation, share.uris.get(0), attachFileCallback); + final Uri uri = share.uris.get(0); + delegateUriPermissionsToService(uri); + xmppConnectionService.attachFileToConversation(conversation, uri, attachFileCallback); finish(); } }; diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index e14efd734..6808a4058 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -540,6 +540,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); |