Commit f4cc98c5 authored by Tommy Steimel's avatar Tommy Steimel Committed by Commit Bot

[Downloads Home] Prevent file URI from being exposed

This CL adds a check in MediaViewerUtils to prevent creating a pending
view intent if the intent will throw a FileUriExposedException. This
will prevent the "Open with" option from showing up.

Bug: 893544
Change-Id: Id32d202a0bd9975bca7a93d2be7dc291cf8aab45
Reviewed-on: https://chromium-review.googlesource.com/c/1302104Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603193}
parent ad8113c4
...@@ -66,7 +66,7 @@ public class MediaViewerUtils { ...@@ -66,7 +66,7 @@ public class MediaViewerUtils {
builder.setCloseButtonIcon(closeIcon); builder.setCloseButtonIcon(closeIcon);
builder.setShowTitle(true); builder.setShowTitle(true);
if (allowExternalAppHandlers) { if (allowExternalAppHandlers && !willExposeFileUri(contentUri)) {
// Create a PendingIntent that can be used to view the file externally. // Create a PendingIntent that can be used to view the file externally.
// TODO(https://crbug.com/795968): Check if this is problematic in multi-window mode, // TODO(https://crbug.com/795968): Check if this is problematic in multi-window mode,
// where two different viewers could be visible at the // where two different viewers could be visible at the
...@@ -83,8 +83,7 @@ public class MediaViewerUtils { ...@@ -83,8 +83,7 @@ public class MediaViewerUtils {
// Create a PendingIntent that shares the file with external apps. // Create a PendingIntent that shares the file with external apps.
// If the URI is a file URI and the Android version is N or later, this will throw a // If the URI is a file URI and the Android version is N or later, this will throw a
// FileUriExposedException. In this case, we just don't add the share button. // FileUriExposedException. In this case, we just don't add the share button.
if (!contentUri.getScheme().equals(ContentResolver.SCHEME_FILE) if (!willExposeFileUri(contentUri)) {
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
PendingIntent pendingShareIntent = PendingIntent.getActivity(context, 0, PendingIntent pendingShareIntent = PendingIntent.getActivity(context, 0,
createShareIntent(contentUri, mimeType), PendingIntent.FLAG_CANCEL_CURRENT); createShareIntent(contentUri, mimeType), PendingIntent.FLAG_CANCEL_CURRENT);
builder.setActionButton( builder.setActionButton(
...@@ -256,4 +255,10 @@ public class MediaViewerUtils { ...@@ -256,4 +255,10 @@ public class MediaViewerUtils {
return MIMETYPE_IMAGE.equals(pieces[0]); return MIMETYPE_IMAGE.equals(pieces[0]);
} }
private static boolean willExposeFileUri(Uri uri) {
// On Android N and later, an Exception is thrown if we try to expose a file:// URI.
return uri.getScheme().equals(ContentResolver.SCHEME_FILE)
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment