diff --git a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java index 006ecb937922c..b7ed70a23038d 100644 --- a/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java +++ b/packages/SystemUI/src/com/android/systemui/theme/ThemeOverlayController.java @@ -254,6 +254,12 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { ColorUtils.RGBToHSL(Color.red(color), Color.green(color), Color.blue(color), hslMain); hslMain[0] /= 360f; + // To close to white or black, let's use the default system theme instead of + // applying a colorized one. + if (hslMain[2] < 0.05 || hslMain[2] > 0.95) { + return Color.TRANSPARENT; + } + float minDistance = Float.MAX_VALUE; int closestColor = Color.TRANSPARENT; for (int candidate: candidates) { @@ -281,7 +287,7 @@ public class ThemeOverlayController extends SystemUI implements Dumpable { final String overlayPackageJson = mSecureSettings.getStringForUser( Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES, currentUser); - if (DEBUG) Log.d(TAG, "updateThemeOverlays: " + overlayPackageJson); + if (DEBUG) Log.d(TAG, "updateThemeOverlays. Setting: " + overlayPackageJson); boolean hasSystemPalette = false; boolean hasAccentColor = false; final Map categoryToPackage = new ArrayMap<>(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java index c826cbcb5389b..e04720a6aa686 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/theme/ThemeOverlayControllerTest.java @@ -147,11 +147,37 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { verifyNoMoreInteractions(mThemeOverlayApplier); } + @Test + public void onWallpaperColorsChanged_whiteTheme() { + WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.WHITE), + Color.valueOf(Color.BLUE), null); + mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM); + ArgumentCaptor> themeOverlays = ArgumentCaptor.forClass(Map.class); + + verify(mThemeOverlayApplier).applyCurrentUserOverlays(themeOverlays.capture(), any()); + + // Assert that we received the colors that we were expecting + assertThat(!themeOverlays.getValue().containsKey(OVERLAY_CATEGORY_SYSTEM_PALETTE)); + } + + @Test + public void onWallpaperColorsChanged_blackTheme() { + WallpaperColors mainColors = new WallpaperColors(Color.valueOf(Color.BLACK), + Color.valueOf(Color.BLUE), null); + mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM); + ArgumentCaptor> themeOverlays = ArgumentCaptor.forClass(Map.class); + + verify(mThemeOverlayApplier).applyCurrentUserOverlays(themeOverlays.capture(), any()); + + // Assert that we received the colors that we were expecting + assertThat(!themeOverlays.getValue().containsKey(OVERLAY_CATEGORY_SYSTEM_PALETTE)); + } + @Test public void onWallpaperColorsChanged_addsLeadingZerosToColors() { // Should ask for a new theme when wallpaper colors change WallpaperColors mainColors = new WallpaperColors(Color.valueOf(0x0CCCCC), - Color.valueOf(0x000111), null); + Color.valueOf(0x000CCC), null); mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM); ArgumentCaptor> themeOverlays = ArgumentCaptor.forClass(Map.class); @@ -161,7 +187,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase { assertThat(themeOverlays.getValue().get(OVERLAY_CATEGORY_SYSTEM_PALETTE)) .isEqualTo(MONET_SYSTEM_PALETTE_PACKAGE + "0CCCCC"); assertThat(themeOverlays.getValue().get(OVERLAY_CATEGORY_ACCENT_COLOR)) - .isEqualTo(MONET_ACCENT_COLOR_PACKAGE + "000111"); + .isEqualTo(MONET_ACCENT_COLOR_PACKAGE + "000CCC"); } @Test