From 9351522eabdfc40b90a159baae99858d4100a8d4 Mon Sep 17 00:00:00 2001 From: Jay Aliomer Date: Fri, 7 May 2021 12:18:54 -0400 Subject: [PATCH] Sample at least 1 pixel from image wallpaper Fixes: b/186879399 Test: ImageWallpaperTest Change-Id: Ieec953f81420e4b7b3ac500f4897cbc33eed59fa --- .../src/com/android/systemui/ImageWallpaper.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java b/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java index 76cec0b334778..64a683e78953a 100644 --- a/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java +++ b/packages/SystemUI/src/com/android/systemui/ImageWallpaper.java @@ -305,10 +305,15 @@ public class ImageWallpaper extends WallpaperService { continue; } Rect subImage = new Rect( - Math.round(area.left * b.getWidth()), - Math.round(area.top * b.getHeight()), - Math.round(area.right * b.getWidth()), - Math.round(area.bottom * b.getHeight())); + (int) Math.floor(area.left * b.getWidth()), + (int) Math.floor(area.top * b.getHeight()), + (int) Math.ceil(area.right * b.getWidth()), + (int) Math.ceil(area.bottom * b.getHeight())); + if (subImage.isEmpty()) { + // Do not notify client. treat it as too small to sample + colors.add(null); + continue; + } Bitmap colorImg = Bitmap.createBitmap(b, subImage.left, subImage.top, subImage.width(), subImage.height()); WallpaperColors color = WallpaperColors.fromBitmap(colorImg);