From 34ec5ad99daa6b3d80d0dd0887e6b41464fee281 Mon Sep 17 00:00:00 2001 From: Serg Date: Mon, 3 Apr 2023 15:58:32 -0400 Subject: [PATCH] Prevents a crash on wallpaper image decode when there is no memory available --- .../ntp_background_images/util/NTPUtil.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java b/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java index 77e39730d87d..b4af4493b403 100644 --- a/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java +++ b/android/java/org/chromium/chrome/browser/ntp_background_images/util/NTPUtil.java @@ -314,16 +314,19 @@ private static Bitmap getBitmapFromImagePath(String imagePath, BitmapFactory.Opt imageBitmap = BitmapFactory.decodeStream(inputStream, null, options); inputStream.close(); } catch (IOException exc) { - Log.e("NTP", exc.getMessage()); + Log.e(TAG, "getBitmapFromImagePath: IOException: " + exc.getMessage()); } catch (IllegalArgumentException exc) { - Log.e("NTP", exc.getMessage()); + Log.e(TAG, "getBitmapFromImagePath: IllegalArgumentException: " + exc.getMessage()); + } catch (OutOfMemoryError exc) { + Log.e(TAG, "getBitmapFromImagePath: OutOfMemoryError: " + exc.getMessage()); } finally { try { if (inputStream != null) { inputStream.close(); } } catch (IOException exception) { - Log.e("NTP", exception.getMessage()); + Log.e(TAG, + "getBitmapFromImagePath IOException in finally: " + exception.getMessage()); return null; } } @@ -399,7 +402,7 @@ public static Bitmap getCalculatedBitmap(Bitmap imageBitmap, float centerPointX, return bitmapWithGradient; } catch (Exception exc) { exc.printStackTrace(); - Log.e("NTP", exc.getMessage()); + Log.e(TAG, "getCalculatedBitmap: " + exc.getMessage()); return null; } finally { if (imageBitmap != null && !imageBitmap.isRecycled()) imageBitmap.recycle(); @@ -418,7 +421,7 @@ public static Bitmap getTopSiteBitmap(String iconPath) { inputStream.close(); } catch (IOException exc) { exc.printStackTrace(); - Log.e("NTP", exc.getMessage()); + Log.e(TAG, "getTopSiteBitmap IOException: " + exc.getMessage()); topSiteIcon = null; } finally { try { @@ -427,7 +430,7 @@ public static Bitmap getTopSiteBitmap(String iconPath) { } } catch (IOException exception) { exception.printStackTrace(); - Log.e("NTP", exception.getMessage()); + Log.e(TAG, "getTopSiteBitmap IOException in finally: " + exception.getMessage()); topSiteIcon = null; } }