delegate uri permission to service when processing files

This commit is contained in:
Daniel Gultsch 2018-01-23 22:02:28 +01:00
parent 0dbad2eea5
commit 676ac32a97
5 changed files with 22 additions and 2 deletions

View file

@ -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) {

View file

@ -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<Message>() {
@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<Message>() {

View file

@ -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 = "*/*";

View file

@ -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<Uri> 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()

View file

@ -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);