From f0f2aab92d9a66a30ab76d263df38f6c227d752d Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 1 Dec 2016 12:09:49 +0100 Subject: [PATCH] made provider authorities relativ to deal with different package ids --- src/main/AndroidManifest.xml | 4 ++-- .../eu/siacs/conversations/persistance/FileBackend.java | 9 +++++++-- .../eu/siacs/conversations/services/BarcodeProvider.java | 7 ++++--- .../eu/siacs/conversations/ui/EditAccountActivity.java | 2 +- .../siacs/conversations/ui/adapter/MessageAdapter.java | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index c1baf42d2..d6991f880 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -197,7 +197,7 @@ diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 1886d3c09..13e27f890 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -60,7 +60,7 @@ import eu.siacs.conversations.xmpp.pep.Avatar; public class FileBackend { private static final SimpleDateFormat IMAGE_DATE_FORMAT = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US); - public static final String CONVERSATIONS_FILE_PROVIDER = "eu.siacs.conversations.files"; + private static final String FILE_PROVIDER = ".files"; private XmppConnectionService mXmppConnectionService; @@ -454,12 +454,17 @@ public class FileBackend { File file = new File(getTakePhotoPath()+"IMG_" + this.IMAGE_DATE_FORMAT.format(new Date()) + ".jpg"); file.getParentFile().mkdirs(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - return FileProvider.getUriForFile(mXmppConnectionService, CONVERSATIONS_FILE_PROVIDER, file); + return getUriForFile(mXmppConnectionService,file); } else { return Uri.fromFile(file); } } + public static Uri getUriForFile(Context context, File file) { + String packageId = context.getPackageName(); + return FileProvider.getUriForFile(context, packageId + FILE_PROVIDER, file); + } + public static Uri getIndexableTakePhotoUri(Uri original) { if ("file".equals(original.getScheme())) { return original; diff --git a/src/main/java/eu/siacs/conversations/services/BarcodeProvider.java b/src/main/java/eu/siacs/conversations/services/BarcodeProvider.java index 8d00b33e1..9c50b0815 100644 --- a/src/main/java/eu/siacs/conversations/services/BarcodeProvider.java +++ b/src/main/java/eu/siacs/conversations/services/BarcodeProvider.java @@ -34,7 +34,7 @@ import eu.siacs.conversations.xmpp.jid.Jid; public class BarcodeProvider extends ContentProvider implements ServiceConnection { - private static final String AUTHORITY = "eu.siacs.conversations.barcodes"; + private static final String AUTHORITY = ".barcodes"; private final Object lock = new Object(); @@ -176,8 +176,9 @@ public class BarcodeProvider extends ContentProvider implements ServiceConnectio } } - public static Uri getUriForAccount(Account account) { - return Uri.parse("content://" + AUTHORITY + "/" + account.getJid().toBareJid() + ".png"); + public static Uri getUriForAccount(Context context, Account account) { + final String packageId = context.getPackageName(); + return Uri.parse("content://" + packageId + AUTHORITY + "/" + account.getJid().toBareJid() + ".png"); } public static Bitmap createAztecBitmap(String input, int size) { diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 008c563b8..e14f559ea 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -763,7 +763,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat private void shareBarcode() { Intent intent = new Intent(Intent.ACTION_SEND); - intent.putExtra(Intent.EXTRA_STREAM,BarcodeProvider.getUriForAccount(mAccount)); + intent.putExtra(Intent.EXTRA_STREAM,BarcodeProvider.getUriForAccount(this,mAccount)); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.setType("image/png"); startActivity(Intent.createChooser(intent, getText(R.string.share_with))); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 5418b344d..2de808952 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -711,7 +711,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie Uri uri; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { - uri = FileProvider.getUriForFile(activity, FileBackend.CONVERSATIONS_FILE_PROVIDER, file); + uri = FileBackend.getUriForFile(activity, file); } catch (IllegalArgumentException e) { Toast.makeText(activity,activity.getString(R.string.no_permission_to_access_x,file.getAbsolutePath()), Toast.LENGTH_SHORT).show(); return;