From e0c7504c921f52270e823f17d10ff68faf60d72d Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Fri, 9 Oct 2020 15:27:41 +0900 Subject: [PATCH] protect against ExifInterface init failure on older devices --- .../aves/channel/calls/MetadataHandler.kt | 23 +++++++++++++------ .../thibault/aves/model/SourceImageEntry.kt | 5 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MetadataHandler.kt b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MetadataHandler.kt index a46db0d68..da9cf4cb1 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MetadataHandler.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/MetadataHandler.kt @@ -121,7 +121,8 @@ class MetadataHandler(private val context: Context) : MethodCallHandler { // fallback to read EXIF via ExifInterface try { StorageUtils.openInputStream(context, uri).use { input -> - val allTags = describeAll(ExifInterface(input)).toMutableMap() + val exif = ExifInterface(input) + val allTags = describeAll(exif).toMutableMap() if (foundXmp) { // do not overwrite XMP parsed by metadata-extractor // with raw XMP found by ExifInterface @@ -129,7 +130,9 @@ class MetadataHandler(private val context: Context) : MethodCallHandler { } metadataMap.putAll(allTags.mapValues { it.value.toMutableMap() }) } - } catch (e: IOException) { + } catch (e: Exception) { + // ExifInterface initialization can fail with a RuntimeException + // caused by an internal MediaMetadataRetriever failure Log.w(LOG_TAG, "failed to get metadata by ExifInterface for uri=$uri", e) } } @@ -291,7 +294,9 @@ class MetadataHandler(private val context: Context) : MethodCallHandler { metadataMap[KEY_LONGITUDE] = latLong[1] } } - } catch (e: IOException) { + } catch (e: Exception) { + // ExifInterface initialization can fail with a RuntimeException + // caused by an internal MediaMetadataRetriever failure Log.w(LOG_TAG, "failed to get metadata by ExifInterface for uri=$uri", e) } } @@ -446,7 +451,9 @@ class MetadataHandler(private val context: Context) : MethodCallHandler { } result.success(metadataMap) } - } catch (e: IOException) { + } catch (e: Exception) { + // ExifInterface initialization can fail with a RuntimeException + // caused by an internal MediaMetadataRetriever failure result.error("getExifInterfaceMetadata-failure", "failed to get exif for uri=$uri", e.message) } } @@ -507,10 +514,12 @@ class MetadataHandler(private val context: Context) : MethodCallHandler { val thumbnails = ArrayList() try { StorageUtils.openInputStream(context, uri).use { input -> - ExifInterface(input).thumbnailBytes?.let { thumbnails.add(it) } + val exif = ExifInterface(input) + exif.thumbnailBytes?.let { thumbnails.add(it) } } - } catch (e: IOException) { - // ignore + } catch (e: Exception) { + // ExifInterface initialization can fail with a RuntimeException + // caused by an internal MediaMetadataRetriever failure } result.success(thumbnails) } diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/model/SourceImageEntry.kt b/android/app/src/main/kotlin/deckers/thibault/aves/model/SourceImageEntry.kt index 7c7f3adc6..d517fda35 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/model/SourceImageEntry.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/model/SourceImageEntry.kt @@ -217,8 +217,9 @@ class SourceImageEntry { exif.getSafeInt(ExifInterface.TAG_ORIENTATION, acceptZero = false) { sourceRotationDegrees = exif.rotationDegrees } exif.getSafeDateMillis(ExifInterface.TAG_DATETIME) { sourceDateTakenMillis = it } } - } catch (e: IOException) { - // ignore + } catch (e: Exception) { + // ExifInterface initialization can fail with a RuntimeException + // caused by an internal MediaMetadataRetriever failure } }