Merge "Allow adding CarSpanIcon to grid item title and text. Test: Test with unit test." into androidx-main
diff --git a/car/app/app/src/main/java/androidx/car/app/model/GridItem.java b/car/app/app/src/main/java/androidx/car/app/model/GridItem.java
index d34e7b5..06304ed 100644
--- a/car/app/app/src/main/java/androidx/car/app/model/GridItem.java
+++ b/car/app/app/src/main/java/androidx/car/app/model/GridItem.java
@@ -251,8 +251,8 @@
         /**
          * Sets the title of the {@link GridItem}.
          *
-         * <p>Only {@link DistanceSpan}s and {@link DurationSpan}s are supported in the input
-         * string.
+         * <p>{@code title} must conform to {@link CarTextConstraints.TEXT_ONLY} in Car API 7 and
+         * below, and {@link CarTextConstraints.TEXT_AND_ICON} in Car API 8 and above.
          *
          * @throws IllegalArgumentException if {@code title} contains unsupported spans
          */
@@ -263,7 +263,7 @@
                 return this;
             }
             CarText titleText = CarText.create(title);
-            CarTextConstraints.TEXT_ONLY.validateOrThrow(titleText);
+            CarTextConstraints.TEXT_AND_ICON.validateOrThrow(titleText);
             mTitle = titleText;
             return this;
         }
@@ -271,8 +271,8 @@
         /**
          * Sets the title of the {@link GridItem}, with support for multiple length variants.
          *
-         * <p>Only {@link DistanceSpan}s and {@link DurationSpan}s are supported in the input
-         * string.
+         * <p>{@code title} must conform to {@link CarTextConstraints.TEXT_ONLY} in Car API 7 and
+         * below, and {@link CarTextConstraints.TEXT_AND_ICON} in Car API 8 and above.
          *
          * @throws IllegalArgumentException if {@code title} contains unsupported spans
          */
@@ -282,7 +282,7 @@
                 mTitle = null;
                 return this;
             }
-            CarTextConstraints.TEXT_ONLY.validateOrThrow(title);
+            CarTextConstraints.TEXT_AND_ICON.validateOrThrow(title);
             mTitle = title;
             return this;
         }
@@ -290,10 +290,9 @@
         /**
          * Sets a secondary text string to the grid item that is displayed below the title.
          *
-         * <p>The text can be customized with {@link ForegroundCarColorSpan},
-         * {@link androidx.car.app.model.DistanceSpan}, and
-         * {@link androidx.car.app.model.DurationSpan} instances, any other spans will be ignored
-         * by the host.
+         * <p>{@code text} must conform to {@link CarTextConstraints.TEXT_WITH_COLORS} in Car API
+         * 7 and below, and {@link CarTextConstraints.TEXT_WITH_COLORS_AND_ICON} in Car API 8 and
+         * above.
          *
          * <h2>Text Wrapping</h2>
          *
@@ -305,7 +304,7 @@
         @NonNull
         public Builder setText(@NonNull CharSequence text) {
             mText = CarText.create(requireNonNull(text));
-            CarTextConstraints.TEXT_WITH_COLORS.validateOrThrow(mText);
+            CarTextConstraints.TEXT_WITH_COLORS_AND_ICON.validateOrThrow(mText);
             return this;
         }
 
@@ -313,10 +312,9 @@
          * Sets a secondary text string to the grid item that is displayed below the title, with
          * support for multiple length variants.
          *
-         * <p>The text can be customized with {@link ForegroundCarColorSpan},
-         * {@link androidx.car.app.model.DistanceSpan}, and
-         * {@link androidx.car.app.model.DurationSpan} instances, any other spans will be ignored
-         * by the host.
+         * <p>{@code text} must conform to {@link CarTextConstraints.TEXT_WITH_COLORS} in Car API
+         * 7 and below, and {@link CarTextConstraints.TEXT_WITH_COLORS_AND_ICON} in Car API 8 and
+         * above.
          *
          * <h2>Text Wrapping</h2>
          *
@@ -328,7 +326,7 @@
         @NonNull
         public Builder setText(@NonNull CarText text) {
             mText = requireNonNull(text);
-            CarTextConstraints.TEXT_WITH_COLORS.validateOrThrow(mText);
+            CarTextConstraints.TEXT_WITH_COLORS_AND_ICON.validateOrThrow(mText);
             return this;
         }
 
diff --git a/car/app/app/src/test/java/androidx/car/app/model/GridItemTest.java b/car/app/app/src/test/java/androidx/car/app/model/GridItemTest.java
index d3ffeb3..19dfdc08 100644
--- a/car/app/app/src/test/java/androidx/car/app/model/GridItemTest.java
+++ b/car/app/app/src/test/java/androidx/car/app/model/GridItemTest.java
@@ -85,11 +85,13 @@
                 IllegalArgumentException.class,
                 () -> new GridItem.Builder().setTitle(title2));
 
-        // DurationSpan and DistanceSpan do not throw
+        // CarIconSpan, DurationSpan and DistanceSpan do not throw
         CharSequence title3 = TestUtils.getCharSequenceWithDistanceAndDurationSpans("Title");
         new GridItem.Builder().setTitle(title3).setImage(BACK).build();
         CarText title4 = TestUtils.getCarTextVariantsWithDistanceAndDurationSpans("Title");
         new GridItem.Builder().setTitle(title4).setImage(BACK).build();
+        CharSequence title5 = TestUtils.getCharSequenceWithIconSpan("Title");
+        new GridItem.Builder().setTitle(title5).setImage(BACK).build();
     }
 
     @Test
@@ -162,11 +164,13 @@
                 IllegalArgumentException.class,
                 () -> new GridItem.Builder().setTitle("Title").setText(text2));
 
-        // DurationSpan and DistanceSpan do not throw
+        // CarIconSpan, DurationSpan and DistanceSpan do not throw
         CharSequence text3 = TestUtils.getCharSequenceWithColorSpan("Text");
         new GridItem.Builder().setTitle("Title").setText(text3).setImage(BACK).build();
         CarText text4 = TestUtils.getCarTextVariantsWithColorSpan("Text");
         new GridItem.Builder().setTitle("Title").setText(text4).setImage(BACK).build();
+        CharSequence text5 = TestUtils.getCharSequenceWithIconSpan("Text");
+        new GridItem.Builder().setTitle("Title").setText(text5).setImage(BACK).build();
     }
 
     @Test