From 05aa7641f7da31569e5ee91ba140cc6a0c61973d Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Tue, 17 May 2022 11:46:52 +0900 Subject: [PATCH] minor fixes --- .../aves/channel/calls/fetchers/RegionFetcher.kt | 2 +- lib/ref/mime_types.dart | 15 ++++++++++++--- lib/services/media/media_file_service.dart | 4 +++- lib/services/storage_service.dart | 9 ++++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/fetchers/RegionFetcher.kt b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/fetchers/RegionFetcher.kt index a4796a3c6..a022bfd8d 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/fetchers/RegionFetcher.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/fetchers/RegionFetcher.kt @@ -77,7 +77,7 @@ class RegionFetcher internal constructor( } } if (newDecoder == null) { - result.error("getRegion-read-null", "failed to open file for uri=$uri regionRect=$regionRect", null) + result.error("getRegion-read-null", "failed to open file for mimeType=$mimeType uri=$uri regionRect=$regionRect", null) return } currentDecoderRef = LastDecoderRef(uri, newDecoder) diff --git a/lib/ref/mime_types.dart b/lib/ref/mime_types.dart index 4cb2f619d..cec770cae 100644 --- a/lib/ref/mime_types.dart +++ b/lib/ref/mime_types.dart @@ -1,6 +1,7 @@ class MimeTypes { static const anyImage = 'image/*'; + static const avif = 'image/avif'; static const bmp = 'image/bmp'; static const bmpX = 'image/x-ms-bmp'; static const gif = 'image/gif'; @@ -66,18 +67,26 @@ class MimeTypes { // groups // formats that support transparency - static const Set alphaImages = {bmp, bmpX, gif, ico, png, svg, tiff, webp}; + static const Set alphaImages = {avif, bmp, bmpX, gif, heic, heif, ico, png, svg, tiff, webp}; static const Set rawImages = {arw, cr2, crw, dcr, dng, erf, k25, kdc, mrw, nef, nrw, orf, pef, raf, raw, rw2, sr2, srf, srw, x3f}; // TODO TLAD [codec] make it dynamic if it depends on OS/lib versions static const Set undecodableImages = {art, cdr, crw, djvu, jxl, psdVnd, psdX, octetStream, zip}; - static const Set _knownOpaqueImages = {heic, heif, jpeg}; + static const Set _knownOpaqueImages = {jpeg}; static const Set _knownVideos = {avi, aviVnd, flv, flvX, mkv, mov, mp2t, mp2ts, mp4, mpeg, ogv, webm}; - static final Set knownMediaTypes = {..._knownOpaqueImages, ...alphaImages, ...rawImages, ...undecodableImages, ..._knownVideos}; + static final Set knownMediaTypes = { + anyImage, + ..._knownOpaqueImages, + ...alphaImages, + ...rawImages, + ...undecodableImages, + anyVideo, + ..._knownVideos, + }; static bool isImage(String mimeType) => mimeType.startsWith('image'); diff --git a/lib/services/media/media_file_service.dart b/lib/services/media/media_file_service.dart index 57b147459..ae4542659 100644 --- a/lib/services/media/media_file_service.dart +++ b/lib/services/media/media_file_service.dart @@ -248,7 +248,9 @@ class PlatformMediaFileService implements MediaFileService { }); if (result != null) return result as Uint8List; } on PlatformException catch (e, stack) { - await reportService.recordError(e, stack); + if (!MimeTypes.knownMediaTypes.contains(mimeType) && MimeTypes.isVisual(mimeType)) { + await reportService.recordError(e, stack); + } } return Uint8List(0); }, diff --git a/lib/services/storage_service.dart b/lib/services/storage_service.dart index f1af3e4d4..6c7b8e45a 100644 --- a/lib/services/storage_service.dart +++ b/lib/services/storage_service.dart @@ -200,7 +200,14 @@ class PlatformStorageService implements StorageService { // `await` here, so that `completeError` will be caught below return await completer.future; } on PlatformException catch (e, stack) { - await reportService.recordError(e, stack); + final message = e.message; + // mute issue in the specific case when an item: + // 1) is a Media Store `file` content, + // 2) has no `images` or `video` entry, + // 3) is in a restricted directory + if (message == null || !message.contains('/external/file/')) { + await reportService.recordError(e, stack); + } } return false; }