From 48b2945860a5be53c07708f46c04ef667af6b04e Mon Sep 17 00:00:00 2001
From: Sally <sallyyuen@google.com>
Date: Wed, 27 Sep 2023 17:09:52 +0000
Subject: [PATCH] Add documentation about errors for announceForAccessibility.

This copies the live region documentation and puts it in the
announceForAccessibility javadocs, so developers see immediately that
they should use error APIs for error UIs.

Test: n/a
Bug: n/a
Change-Id: I9a7819d82b8ffdf779c7a6851e09fa8a9a55d361
---
 core/java/android/view/View.java | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 4d53b2c6b821..c241fc42dd91 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -8537,6 +8537,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
      * announcements every time a View is updated.
      *
      * <p>
+     * For notifying users about errors, such as in a login screen with text that displays an
+     * "incorrect password" notification, that view should send an AccessibilityEvent of type
+     * {@link AccessibilityEvent#CONTENT_CHANGE_TYPE_ERROR} and set
+     * {@link AccessibilityNodeInfo#setError(CharSequence)} instead. Custom widgets should expose
+     * error-setting methods that support accessibility automatically. For example, instead of
+     * explicitly sending this event when using a TextView, use
+     * {@link android.widget.TextView#setError(CharSequence)}.
+     *
+     * <p>
      * Use {@link #setStateDescription(CharSequence)} to convey state changes to views within the
      * user interface. While a live region may send different types of events generated by the view,
      * state description will send {@link AccessibilityEvent#TYPE_WINDOW_CONTENT_CHANGED} events of
-- 
GitLab