From a358d7611ccf1a2a55da137ef3f8067ebac154e2 Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Mon, 19 Nov 2018 18:25:34 +0800 Subject: Set minimum scaled width/height to 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Applications could be launched on a secondary display that has lower density than default display. While some applications may use 1x1 image resource as activity background, the scaled width/height would be 0 if down scaling the 1x1 image with scale ratio that is less than 1/2. Making sure the scaled width/height won’t less than 1 to prevent application crashed. Bug: 117749148 Test: Launch app on secondary display Change-Id: I73567dd237736466d0bc423485359d50073d86c1 --- graphics/java/android/graphics/ImageDecoder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphics/java/android/graphics/ImageDecoder.java b/graphics/java/android/graphics/ImageDecoder.java index 009e042f74a7..e3b165ccaf34 100644 --- a/graphics/java/android/graphics/ImageDecoder.java +++ b/graphics/java/android/graphics/ImageDecoder.java @@ -1869,8 +1869,8 @@ public final class ImageDecoder implements AutoCloseable { } float scale = (float) dstDensity / srcDensity; - int scaledWidth = (int) (mWidth * scale + 0.5f); - int scaledHeight = (int) (mHeight * scale + 0.5f); + int scaledWidth = Math.max((int) (mWidth * scale + 0.5f), 1); + int scaledHeight = Math.max((int) (mHeight * scale + 0.5f), 1); this.setTargetSize(scaledWidth, scaledHeight); return dstDensity; } -- cgit v1.2.3-59-g8ed1b