From 5c97ff23a37d7b3588dced019ee09731a5e9b9cd Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Wed, 31 Aug 2016 10:25:38 -0700 Subject: [PATCH] Wallpaper: Fix letterboxing if wallpaper is scaled but not cropped Fixes a bug where the wrong part of an image was decoded if the image needed to be scaled but not cropped. Change-Id: I011e59d85b526097ef1daabd63805c7cdc74c17b Fixes: 31112957 --- .../server/wallpaper/WallpaperManagerService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index 3fd4b37c6f423..536e646368d03 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -352,9 +352,17 @@ public class WallpaperManagerService extends IWallpaperManager.Stub { (cropHint.right > options.outWidth ? options.outWidth - cropHint.right : 0), (cropHint.bottom > options.outHeight ? options.outHeight - cropHint.bottom : 0)); + // If the crop hint was larger than the image we just overshot. Patch things up. + if (cropHint.left < 0) { + cropHint.left = 0; + } + if (cropHint.top < 0) { + cropHint.top = 0; + } + // Don't bother cropping if what we're left with is identity needCrop = (options.outHeight > cropHint.height() - && options.outWidth > cropHint.width()); + || options.outWidth > cropHint.width()); } // scale if the crop height winds up not matching the recommended metrics