commit d00611cec519373705b83ed2ac89e1db58532fa2 Author: Jan Henning jh+bugzilla@buttercookie.de Date: Sat May 12 23:17:38 2018 +0200
Bug 1450449 - Part 3: Starting from Nougat, share images via content:// URIs. r=jchen
For sharing images we download the image to a temporary file in our internal storage area. This is a perfect use case for granting temporary access to the file only via a content:// URI instead of directly exposing the real file system path.
Since support for content:// URIs by arbitrary other apps might be patchy on older Android versions, though, we only start doing this from Nougat onwards.
MozReview-Commit-ID: E2I1t8dZzKj
--HG-- extra : rebase_source : 84449c39aed622a995e7e009b8e33d21ff02db23 --- .../org/mozilla/gecko/widget/GeckoActionProvider.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java b/mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java index 056a799f1caa..79854e2931bc 100644 --- a/mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java +++ b/mobile/android/base/java/org/mozilla/gecko/widget/GeckoActionProvider.java @@ -8,9 +8,11 @@ package org.mozilla.gecko.widget; import android.app.Activity; import android.net.Uri; import android.support.design.widget.Snackbar; +import android.support.v4.content.FileProvider; import android.util.Base64; import android.view.Menu;
+import org.mozilla.gecko.AppConstants; import org.mozilla.gecko.GeckoApp; import org.mozilla.gecko.R; import org.mozilla.gecko.SnackbarBuilder; @@ -328,7 +330,7 @@ public class GeckoActionProvider { os.write(buf);
// Only alter the intent when we're sure everything has worked - intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile)); + addFileExtra(intent, imageFile); } else { InputStream is = null; try { @@ -346,7 +348,7 @@ public class GeckoActionProvider { }
// Only alter the intent when we're sure everything has worked - intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(imageFile)); + addFileExtra(intent, imageFile); } finally { IOUtils.safeStreamClose(is); } @@ -357,4 +359,15 @@ public class GeckoActionProvider { IOUtils.safeStreamClose(os); } } + + private void addFileExtra(final Intent intent, final File file) { + if (AppConstants.Versions.preN) { + intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); + } else { + Uri contentUri = FileProvider.getUriForFile(mContext, + AppConstants.MOZ_FILE_PROVIDER_AUTHORITY, file); + intent.putExtra(Intent.EXTRA_STREAM, contentUri); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + } + } }