Improved image error handling

This commit is contained in:
M66B 2020-09-10 09:30:31 +02:00
parent 243996bc4d
commit 8f3bf1ab21
1 changed files with 10 additions and 3 deletions

View File

@ -544,7 +544,7 @@ class ImageHelper {
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length); return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
} }
private static Drawable getCachedImage(Context context, long id, String source) throws IOException { private static Drawable getCachedImage(Context context, long id, String source) {
if (id < 0) if (id < 0)
return null; return null;
@ -557,7 +557,12 @@ class ImageHelper {
DisplayMetrics dm = context.getResources().getDisplayMetrics(); DisplayMetrics dm = context.getResources().getDisplayMetrics();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
return getScaledDrawable(context, file, dm.widthPixels); try {
return getScaledDrawable(context, file, dm.widthPixels);
} catch (IOException ex) {
Log.i(ex);
return null;
}
Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath()); Bitmap bm = BitmapFactory.decodeFile(file.getAbsolutePath());
if (bm != null) { if (bm != null) {
@ -660,7 +665,7 @@ class ImageHelper {
} }
@RequiresApi(api = Build.VERSION_CODES.P) @RequiresApi(api = Build.VERSION_CODES.P)
static Drawable getScaledDrawable(Context context, File file, int scaleToPixels) { static Drawable getScaledDrawable(Context context, File file, int scaleToPixels) throws IOException {
Drawable d; Drawable d;
try { try {
@ -680,6 +685,8 @@ class ImageHelper {
}); });
} catch (Throwable ex) { } catch (Throwable ex) {
Log.i(ex); Log.i(ex);
if (ex instanceof IOException)
throw ex;
/* /*
Samsung: Samsung:
android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'unimplemented'Input contained an error. android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'unimplemented'Input contained an error.