From 70cfb49c65c91a0a3423613def4502b33a0a4d2a Mon Sep 17 00:00:00 2001 From: James O'Leary Date: Mon, 7 Jun 2021 14:10:17 -0400 Subject: [PATCH] Sort colors from high count => low count The colors were being sorted by population ascending, sorting by population descending fixes a long-standing flaky test that became a 100% reproducible failure once scaling fixes were introduced. The test failure that caught this is CTS' WallpaperManagerTest's method wallpaperColors_secondary. It creates a bitmap that is mostly red, with a smaller area of blue. Before the set of 4 CLs in this topic, when the wallpaper was downscaled by WallpaperManager, it introduced new colors to the wallpaper due to bilinear filtering and JPEG compression. With the new colors introduced by scaling, the least popular color was blue enough to pass WallpaperManagerTest's wallpaperColors_primary method, and the 2nd least popular color was red enough to pass wallpaperColors_secondary. With CLs for consistent image input to quantizers, namely 2 CLs, cache wallpaper as PNG instead of JPEG, and only rescale the wallpaper if it is greater than the display height, the scaling/JPEG artifacts are not introduced, which then exposes the bug that primary/secondary were the least popular/2nd least popular colors in the image, instead of the most popular/2nd most popular, as intended. Bug: 188373181 Test: atest CtsAppTestCases:android.app.cts.WallpaperManagerTest #wallpaperColors_secondary --, use helper methods to store the bitmap after downscaling to confirm introduction of new colors before other CLs in this topic, use go/monetstudio to confirm quantization results from that downscaled image. Check test against all 4 CLs, confirm test starts failing once "Only rescale wallpaper if its > display height" CL is introduced. Change-Id: I143f824fbd961b81604d427a0570b3a171bdeb79 --- core/java/android/app/WallpaperColors.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/app/WallpaperColors.java b/core/java/android/app/WallpaperColors.java index b9e5c090a4870..fab9e02f5873e 100644 --- a/core/java/android/app/WallpaperColors.java +++ b/core/java/android/app/WallpaperColors.java @@ -293,7 +293,7 @@ public final class WallpaperColors implements Parcelable { ArrayList> mapEntries = new ArrayList( populationByColor.entrySet()); mapEntries.sort((a, b) -> - a.getValue().compareTo(b.getValue()) + b.getValue().compareTo(a.getValue()) ); mMainColors = mapEntries.stream().map(entry -> Color.valueOf(entry.getKey())).collect( Collectors.toList());