Avoid setting empty content description on elements that don't have a content description. This marks the element as important for accessibility even though it has no a11y data.

PiperOrigin-RevId: 261165409
Change-Id: Ia46541e13d04eac322be4cbeb7427eb8066c7caa
diff --git a/src/main/java/com/google/android/libraries/feed/piet/ElementAdapter.java b/src/main/java/com/google/android/libraries/feed/piet/ElementAdapter.java
index 8017458..50a008d 100644
--- a/src/main/java/com/google/android/libraries/feed/piet/ElementAdapter.java
+++ b/src/main/java/com/google/android/libraries/feed/piet/ElementAdapter.java
@@ -292,9 +292,13 @@
       }
     }
 
-    getBaseView()
-        .setContentDescription(
-            getAccessibilityString(baseElement.getAccessibility(), frameContext));
+    CharSequence contentDescription =
+        getAccessibilityString(baseElement.getAccessibility(), frameContext);
+    if (contentDescription.length() > 0) {
+      getBaseView().setContentDescription(contentDescription);
+    } else {
+      getBaseView().setContentDescription(null);
+    }
     LogDataCallback callback = parameters.hostProviders.getLogDataCallback();
     if (callback != null) {
       switch (baseElement.getLogDataValueCase()) {
diff --git a/src/test/java/com/google/android/libraries/feed/piet/ElementAdapterTest.java b/src/test/java/com/google/android/libraries/feed/piet/ElementAdapterTest.java
index 0a87520..5ce849d 100644
--- a/src/test/java/com/google/android/libraries/feed/piet/ElementAdapterTest.java
+++ b/src/test/java/com/google/android/libraries/feed/piet/ElementAdapterTest.java
@@ -856,7 +856,7 @@
 
     adapter.bindModel(Element.getDefaultInstance(), frameContext);
 
-    assertThat(adapter.getView().getContentDescription().toString()).isEmpty();
+    assertThat(adapter.getView().getContentDescription()).isNull();
   }
 
   @Test