Pick the primary color as the best color to use.

Previously, the best color was picked by checking the colors
against the blacklist. The logic was for picking the best color
was broken When the blacklist was removed for
b/124180048.

Fixes: b129762944
Test: New test points added to TonalTest.java
Change-Id: Ie51806735910bb40e5e66d7baf545ea213e4a01e
diff --git a/core/java/com/android/internal/colorextraction/types/Tonal.java b/core/java/com/android/internal/colorextraction/types/Tonal.java
index 9d85a03..b9aab21 100644
--- a/core/java/com/android/internal/colorextraction/types/Tonal.java
+++ b/core/java/com/android/internal/colorextraction/types/Tonal.java
@@ -109,42 +109,20 @@
         final int mainColorsSize = mainColors.size();
         final int hints = inWallpaperColors.getColorHints();
         final boolean supportsDarkText = (hints & WallpaperColors.HINT_SUPPORTS_DARK_TEXT) != 0;
-        final boolean generatedFromBitmap = (hints & WallpaperColors.HINT_FROM_BITMAP) != 0;
 
         if (mainColorsSize == 0) {
             return false;
         }
 
-        // Decide what's the best color to use.
-        // We have 2 options:
-        // • Just pick the primary color
-        // • Filter out blacklisted colors. This is useful when palette is generated
-        //   automatically from a bitmap.
-        Color bestColor = null;
-        final float[] hsl = new float[3];
-        for (int i = 0; i < mainColorsSize; i++) {
-            final Color color = mainColors.get(i);
-            final int colorValue = color.toArgb();
-            ColorUtils.RGBToHSL(Color.red(colorValue), Color.green(colorValue),
-                    Color.blue(colorValue), hsl);
-
-            // Stop when we find a color that meets our criteria
-            if (!generatedFromBitmap) {
-                bestColor = color;
-                break;
-            }
-        }
-
-        // Fail if not found
-        if (bestColor == null) {
-            return false;
-        }
+        // Pick the primary color as the best color to use.
+        final Color bestColor = mainColors.get(0);
 
         // Tonal is not really a sort, it takes a color from the extracted
         // palette and finds a best fit amongst a collection of pre-defined
         // palettes. The best fit is tweaked to be closer to the source color
         // and replaces the original palette.
         int colorValue = bestColor.toArgb();
+        final float[] hsl = new float[3];
         ColorUtils.RGBToHSL(Color.red(colorValue), Color.green(colorValue), Color.blue(colorValue),
                 hsl);
 
diff --git a/tests/Internal/Android.bp b/tests/Internal/Android.bp
index 4cb9f8d5..e233fed 100644
--- a/tests/Internal/Android.bp
+++ b/tests/Internal/Android.bp
@@ -10,6 +10,7 @@
         "junit",
         "androidx.test.rules",
         "mockito-target-minus-junit4",
+        "truth-prebuilt",
     ],
     java_resource_dirs: ["res"],
     certificate: "platform",
diff --git a/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java b/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java
index 300182d..768e47c 100644
--- a/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java
+++ b/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java
@@ -15,6 +15,8 @@
  */
 package com.android.internal.colorextraction.types;
 
+import static com.google.common.truth.Truth.assertThat;
+
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
@@ -67,6 +69,36 @@
     }
 
     @Test
+    public void extractInto_fromBitmap() {
+        Tonal tonal = new Tonal(InstrumentationRegistry.getContext());
+        GradientColors normal = new GradientColors();
+        GradientColors dark = new GradientColors();
+        GradientColors extraDark = new GradientColors();
+        WallpaperColors wallColors = new WallpaperColors(Color.valueOf(Color.RED), null, null,
+                WallpaperColors.HINT_FROM_BITMAP);
+
+        // WHEN colors are extracted from a wallpaper with only a red primary color.
+        tonal.extractInto(wallColors, normal, dark, extraDark);
+        // THEN the main extracted color is red
+        assertThat(normal.getMainColor()).isEqualTo(Color.RED);
+    }
+
+    @Test
+    public void extractInto_supportsDarkText() {
+        Tonal tonal = new Tonal(InstrumentationRegistry.getContext());
+        GradientColors normal = new GradientColors();
+        GradientColors dark = new GradientColors();
+        GradientColors extraDark = new GradientColors();
+        WallpaperColors wallColors = new WallpaperColors(Color.valueOf(Color.RED), null, null,
+                WallpaperColors.HINT_SUPPORTS_DARK_TEXT);
+
+        // WHEN colors are extracted from a wallpaper with only a red primary color.
+        tonal.extractInto(wallColors, normal, dark, extraDark);
+        // THEN the main extracted color is red
+        assertThat(normal.getMainColor()).isEqualTo(Color.RED);
+    }
+
+    @Test
     public void colorRange_containsColor() {
         Tonal.ColorRange colorRange = new Tonal.ColorRange(new Range<>(0f, 50f),
                 new Range<>(0f, 1f), new Range<>(0f, 1f));