diff options
| author | 2023-03-27 17:57:42 -0700 | |
|---|---|---|
| committer | 2023-03-28 09:20:22 -0700 | |
| commit | 4c421ccd6e61636dca7fddc58f0f7205d092623a (patch) | |
| tree | 5d1cd2f8646049c9eecce8fb32e1fecf26557d75 /java/src/com | |
| parent | 9c1f13565a33f4846aa9255ba74b0ef1c49b972a (diff) | |
Print special logcat warning SecurityException
If a SecurityException is thrown while trying to read data for a
provided URI, print a special warning suggesting granting URI
permissions.
Bug: 273890881
Test: use test application to check that the warning is printed
Change-Id: I7de6b8bade1c90943bc105e4648f12daa3b6580f
Diffstat (limited to 'java/src/com')
| -rw-r--r-- | java/src/com/android/intentresolver/contentpreview/ChooserContentPreviewUi.java | 19 |
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."); + } } |