Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 484bd16e authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Fix issue with white and black themes

They were being mapped to other colored overlays instead of defaulting
to the main device theme.

Fixes: 174674800
Test: manual
Test: atest ThemeOverlayControllerTest
Change-Id: I89e758255292dcca8065fb6461e1a79ae7f3a172
parent 5b902270
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -267,6 +267,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) {
@@ -294,7 +300,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<String, String> categoryToPackage = new ArrayMap<>();
@@ -343,6 +349,10 @@ public class ThemeOverlayController extends SystemUI implements Dumpable {
        while (colorString.length() < 6) {
            colorString = "0" + colorString;
        }
        // Remove alpha component
        if (colorString.length() > 6) {
            colorString = colorString.substring(colorString.length() - 6);
        }
        return colorString;
    }

+31 −7
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
                eq(UserHandle.USER_ALL));
        verify(mDumpManager).registerDumpable(any(), any());

        List<Integer> colorList = List.of(Color.RED, Color.BLUE, 0x0CCCCC, 0x000111);
        List<Integer> colorList = List.of(Color.RED, Color.BLUE, 0x0CCCCC, 0x000CCC);
        when(mThemeOverlayApplier.getAvailableAccentColors()).thenReturn(colorList);
        when(mThemeOverlayApplier.getAvailableSystemColors()).thenReturn(colorList);
    }
@@ -136,22 +136,46 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {

        // Assert that we received the colors that we were expecting
        assertThat(themeOverlays.getValue().get(OVERLAY_CATEGORY_SYSTEM_PALETTE))
                .isEqualTo(MONET_SYSTEM_PALETTE_PACKAGE
                        + Integer.toHexString(Color.RED).toUpperCase());
                .isEqualTo(MONET_SYSTEM_PALETTE_PACKAGE + "FF0000");
        assertThat(themeOverlays.getValue().get(OVERLAY_CATEGORY_ACCENT_COLOR))
                .isEqualTo(MONET_ACCENT_COLOR_PACKAGE
                        + Integer.toHexString(Color.BLUE).toUpperCase());
                .isEqualTo(MONET_ACCENT_COLOR_PACKAGE + "0000FF");

        // Should not ask again if changed to same value
        mColorsListener.getValue().onColorsChanged(mainColors, WallpaperManager.FLAG_SYSTEM);
        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<Map<String, String>> 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)).isFalse();
    }

    @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<Map<String, String>> 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)).isFalse();
    }

    @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<Map<String, String>> themeOverlays = ArgumentCaptor.forClass(Map.class);

@@ -161,7 +185,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