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

[Media Intent Handler] Prevent crashing when unable to query

This CL adds a try/catch block to prevent SecurityExceptions from
crashing media opened via the media intent handler. In certain cases,
we don't have permission to query for the file display name. In those
cases, instead of crashing we will instead just fall back to having no
display name.

Bug: 874149
Change-Id: I18ed34655e093cf04c9cb745eeeb6182c8fe28b6
Reviewed-on: https://chromium-review.googlesource.com/1175212Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Commit-Queue: Tommy Steimel <steimel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583312}
parent 23c7886b
...@@ -221,10 +221,17 @@ public abstract class ContentUriUtils { ...@@ -221,10 +221,17 @@ public abstract class ContentUriUtils {
@CalledByNative @CalledByNative
public static String maybeGetDisplayName(String uriString) { public static String maybeGetDisplayName(String uriString) {
Uri uri = Uri.parse(uriString); Uri uri = Uri.parse(uriString);
String displayName = getDisplayName(
uri, ContextUtils.getApplicationContext(), MediaStore.MediaColumns.DISPLAY_NAME);
return TextUtils.isEmpty(displayName) ? null : displayName; try {
String displayName = getDisplayName(uri, ContextUtils.getApplicationContext(),
MediaStore.MediaColumns.DISPLAY_NAME);
return TextUtils.isEmpty(displayName) ? null : displayName;
} catch (SecurityException e) {
Log.w(TAG, "Cannot open content uri: " + uriString, e);
}
// If we are unable to query the content URI, just return null.
return null;
} }
/** /**
......
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