crashfix when opening image

This commit is contained in:
Thibault Deckers 2021-10-05 17:32:06 +09:00
parent 90758a5ea1
commit db6b47b351
3 changed files with 5 additions and 5 deletions

View file

@ -109,7 +109,7 @@ class ImageByteStreamHandler(private val activity: Activity, private val argumen
private fun streamImageAsIs(uri: Uri, mimeType: String) { private fun streamImageAsIs(uri: Uri, mimeType: String) {
try { try {
StorageUtils.openInputStream(activity, uri)?.use { input -> streamBytes(input) } StorageUtils.openInputStream(activity, uri)?.use { input -> streamBytes(input) }
} catch (e: IOException) { } catch (e: Exception) {
error("streamImage-image-read-exception", "failed to get image for mimeType=$mimeType uri=$uri", e.message) error("streamImage-image-read-exception", "failed to get image for mimeType=$mimeType uri=$uri", e.message)
} }
} }

View file

@ -448,10 +448,9 @@ object StorageUtils {
val effectiveUri = getOriginalUri(context, uri) val effectiveUri = getOriginalUri(context, uri)
return try { return try {
context.contentResolver.openInputStream(effectiveUri) context.contentResolver.openInputStream(effectiveUri)
} catch (e: FileNotFoundException) { } catch (e: Exception) {
Log.w(LOG_TAG, "failed to find file at uri=$effectiveUri") // among various other exceptions,
null // opening a file marked pending and owned by another package throws an `IllegalStateException`
} catch (e: SecurityException) {
Log.w(LOG_TAG, "failed to open file at uri=$effectiveUri", e) Log.w(LOG_TAG, "failed to open file at uri=$effectiveUri", e)
null null
} }

View file

@ -72,6 +72,7 @@ class _HomePageState extends State<HomePage> {
final intentData = widget.intentData ?? await ViewerService.getIntentData(); final intentData = widget.intentData ?? await ViewerService.getIntentData();
if (intentData.isNotEmpty) { if (intentData.isNotEmpty) {
final action = intentData['action']; final action = intentData['action'];
await reportService.log('Intent action=$action');
switch (action) { switch (action) {
case 'view': case 'view':
_viewerEntry = await _initViewerEntry( _viewerEntry = await _initViewerEntry(