Handle SecurityException in ClipData.Item.coerceToText

Catch SecurityException and print a log warning.

The most likely reason for such SecurityException is
a drag and drop operation with a resource (such as a file)
for which the recipient app has no permissions.

Bug: 34716083
Test: Drag a file from Files app to Docs, Docs should not crash
Change-Id: Ib4ebbb01bd3ca87b221e15fac769368272ff4fc4
This commit is contained in:
Vladislav Kaznacheev
2017-01-27 16:39:13 -08:00
parent e244fd33b1
commit b143ff6b6c

View File

@@ -353,6 +353,9 @@ public class ClipData implements Parcelable {
}
return builder.toString();
} catch (SecurityException e) {
Log.w("ClipData", "Failure opening stream", e);
} catch (FileNotFoundException e) {
// Unable to open content URI as text... not really an
// error, just something to ignore.
@@ -536,6 +539,9 @@ public class ClipData implements Parcelable {
return Html.escapeHtml(text);
}
} catch (SecurityException e) {
Log.w("ClipData", "Failure opening stream", e);
} catch (FileNotFoundException e) {
// Unable to open content URI as text... not really an
// error, just something to ignore.