summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java19
1 files changed, 16 insertions, 3 deletions
diff --git a/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java b/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java
index 6892b32c..3509c67d 100644
--- a/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java
+++ b/java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java
@@ -369,30 +369,36 @@ public final class ChooserContentPreviewUi {
private static String getType(ContentInterface resolver, Uri uri) {
try {
return resolver.getType(uri);
+ } catch (SecurityException e) {
+ logProviderPermissionWarning(uri, "mime type");
} catch (Throwable t) {
Log.e(ContentPreviewUi.TAG, "Failed to read content type, uri: " + uri, t);
- return null;
}
+ return null;
}
@Nullable
private static Cursor query(ContentInterface resolver, Uri uri) {
try {
return resolver.query(uri, null, null, null);
+ } catch (SecurityException e) {
+ logProviderPermissionWarning(uri, "metadata");
} catch (Throwable t) {
Log.e(ContentPreviewUi.TAG, "Failed to read metadata, uri: " + uri, t);
- return null;
}
+ return null;
}
@Nullable
private static String[] getStreamTypes(ContentInterface resolver, Uri uri) {
try {
return resolver.getStreamTypes(uri, "*/*");
+ } catch (SecurityException e) {
+ logProviderPermissionWarning(uri, "stream types");
} catch (Throwable t) {
Log.e(ContentPreviewUi.TAG, "Failed to read stream types, uri: " + uri, t);
- return null;
}
+ return null;
}
private static String getFileName(Uri uri) {
@@ -404,4 +410,11 @@ public final class ChooserContentPreviewUi {
}
return fileName;
}
+
+ private static void logProviderPermissionWarning(Uri uri, String dataName) {
+ // The ContentResolver already logs the exception. Log something more informative.
+ Log.w(ContentPreviewUi.TAG, "Could not read " + uri + " " + dataName + "."
+ + " If a preview is desired, call Intent#setClipData() to ensure that the"
+ + " sharesheet is given permission.");
+ }
}