protect against ExifInterface init failure on older devices
This commit is contained in:
parent
c2a096fc91
commit
e0c7504c92
2 changed files with 19 additions and 9 deletions
|
@ -121,7 +121,8 @@ class MetadataHandler(private val context: Context) : MethodCallHandler {
|
||||||
// fallback to read EXIF via ExifInterface
|
// fallback to read EXIF via ExifInterface
|
||||||
try {
|
try {
|
||||||
StorageUtils.openInputStream(context, uri).use { input ->
|
StorageUtils.openInputStream(context, uri).use { input ->
|
||||||
val allTags = describeAll(ExifInterface(input)).toMutableMap()
|
val exif = ExifInterface(input)
|
||||||
|
val allTags = describeAll(exif).toMutableMap()
|
||||||
if (foundXmp) {
|
if (foundXmp) {
|
||||||
// do not overwrite XMP parsed by metadata-extractor
|
// do not overwrite XMP parsed by metadata-extractor
|
||||||
// with raw XMP found by ExifInterface
|
// with raw XMP found by ExifInterface
|
||||||
|
@ -129,7 +130,9 @@ class MetadataHandler(private val context: Context) : MethodCallHandler {
|
||||||
}
|
}
|
||||||
metadataMap.putAll(allTags.mapValues { it.value.toMutableMap() })
|
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)
|
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]
|
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)
|
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)
|
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)
|
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<ByteArray>()
|
val thumbnails = ArrayList<ByteArray>()
|
||||||
try {
|
try {
|
||||||
StorageUtils.openInputStream(context, uri).use { input ->
|
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) {
|
} catch (e: Exception) {
|
||||||
// ignore
|
// ExifInterface initialization can fail with a RuntimeException
|
||||||
|
// caused by an internal MediaMetadataRetriever failure
|
||||||
}
|
}
|
||||||
result.success(thumbnails)
|
result.success(thumbnails)
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,8 +217,9 @@ class SourceImageEntry {
|
||||||
exif.getSafeInt(ExifInterface.TAG_ORIENTATION, acceptZero = false) { sourceRotationDegrees = exif.rotationDegrees }
|
exif.getSafeInt(ExifInterface.TAG_ORIENTATION, acceptZero = false) { sourceRotationDegrees = exif.rotationDegrees }
|
||||||
exif.getSafeDateMillis(ExifInterface.TAG_DATETIME) { sourceDateTakenMillis = it }
|
exif.getSafeDateMillis(ExifInterface.TAG_DATETIME) { sourceDateTakenMillis = it }
|
||||||
}
|
}
|
||||||
} catch (e: IOException) {
|
} catch (e: Exception) {
|
||||||
// ignore
|
// ExifInterface initialization can fail with a RuntimeException
|
||||||
|
// caused by an internal MediaMetadataRetriever failure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue