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

Commit 82e236d7 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

The logic for not populating text to some accessibility events is scattered.

1. Some accessibility evenents should not and were not dispatched for
   text population but there was no centralized location for enforcing
   this - rather the system was firing them in a specific way or there
   were conditions in a few places enforcing that. Now this is centralized
   and clean.

2. Updated the documentation with some new event types the were lacking.

3. Explicitly stated in the documentaition which events are dispatched to
   the sub-tree of the source for text populatation.

bug:5394527

Change-Id: I86e383807d777019ac98b970c7d9d02a2f7afac6
parent 3fd8275c
Loading
Loading
Loading
Loading
+20 −7
Original line number Original line Diff line number Diff line
@@ -1486,6 +1486,18 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
                | VIEW_STATE_PRESSED];
                | VIEW_STATE_PRESSED];
    }
    }
    /**
     * Accessibility event types that are dispatched for text population.
     */
    private static final int POPULATING_ACCESSIBILITY_EVENT_TYPES =
            AccessibilityEvent.TYPE_VIEW_CLICKED
            | AccessibilityEvent.TYPE_VIEW_LONG_CLICKED
            | AccessibilityEvent.TYPE_VIEW_SELECTED
            | AccessibilityEvent.TYPE_VIEW_FOCUSED
            | AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
            | AccessibilityEvent.TYPE_VIEW_HOVER_ENTER
            | AccessibilityEvent.TYPE_VIEW_HOVER_EXIT;
    /**
    /**
     * Temporary Rect currently for use in setBackground().  This will probably
     * Temporary Rect currently for use in setBackground().  This will probably
     * be extended in the future to hold our own class with more than just
     * be extended in the future to hold our own class with more than just
@@ -3855,7 +3867,10 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
            return;
            return;
        }
        }
        onInitializeAccessibilityEvent(event);
        onInitializeAccessibilityEvent(event);
        // Only a subset of accessibility events populates text content.
        if ((event.getEventType() & POPULATING_ACCESSIBILITY_EVENT_TYPES) != 0) {
            dispatchPopulateAccessibilityEvent(event);
            dispatchPopulateAccessibilityEvent(event);
        }
        // In the beginning we called #isShown(), so we know that getParent() is not null.
        // In the beginning we called #isShown(), so we know that getParent() is not null.
        getParent().requestSendAccessibilityEvent(this, event);
        getParent().requestSendAccessibilityEvent(this, event);
    }
    }
@@ -3876,6 +3891,10 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)}
     * {@link AccessibilityDelegate#dispatchPopulateAccessibilityEvent(View, AccessibilityEvent)}
     * is responsible for handling this call.
     * is responsible for handling this call.
     * </p>
     * </p>
     * <p>
     * <em>Note:</em> Accessibility events of certain types are not dispatched for
     * populating the event text via this method. For details refer to {@link AccessibilityEvent}.
     * </p>
     *
     *
     * @param event The event.
     * @param event The event.
     *
     *
@@ -3895,12 +3914,6 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
     * Note: Called from the default {@link AccessibilityDelegate}.
     * Note: Called from the default {@link AccessibilityDelegate}.
     */
     */
    boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
    boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
        // Do not populate text to scroll events. They describe position change
        // and usually come from container with a lot of text which is not very
        // informative for accessibility purposes. Also they are fired frequently.
        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
            return true;
        }
        onPopulateAccessibilityEvent(event);
        onPopulateAccessibilityEvent(event);
        return false;
        return false;
    }
    }
+1 −12
Original line number Original line Diff line number Diff line
@@ -4820,18 +4820,7 @@ public final class ViewRootImpl extends Handler implements ViewParent,


        public void run() {
        public void run() {
            if (mView != null) {
            if (mView != null) {
                // Check again for accessibility state since this is executed delayed.
                mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
                AccessibilityManager accessibilityManager =
                    AccessibilityManager.getInstance(mView.mContext);
                if (accessibilityManager.isEnabled()) {
                    // Send the event directly since we do not want to append the
                    // source text because this is the text for the entire window
                    // and we just want to notify that the content has changed.
                    AccessibilityEvent event = AccessibilityEvent.obtain(
                            AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
                    mView.onInitializeAccessibilityEvent(event);
                    accessibilityManager.sendAccessibilityEvent(event);
                }
                mIsPending = false;
                mIsPending = false;
            }
            }
        }
        }
+154 −13
Original line number Original line Diff line number Diff line
@@ -69,14 +69,16 @@ import java.util.List;
 * <em>Type:</em>{@link #TYPE_VIEW_CLICKED}</br>
 * <em>Type:</em>{@link #TYPE_VIEW_CLICKED}</br>
 * <em>Properties:</em></br>
 * <em>Properties:</em></br>
 * <ul>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getText()} - The text of the source.</li>
 *   <li>{@link #getText()} - The text of the source's sub-tree.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #isPassword()} - Whether the source is password.</li>
 *   <li>{@link #isPassword()} - Whether the source is password.</li>
 *   <li>{@link #isChecked()} - Whether the source is checked.</li>
 *   <li>{@link #isChecked()} - Whether the source is checked.</li>
 *   <li>{@link #getContentDescription()} - The content description of the source.</li>
 * </ul>
 * </ul>
 * </p>
 * </p>
 * <p>
 * <p>
@@ -85,14 +87,16 @@ import java.util.List;
 * <em>Type:</em>{@link #TYPE_VIEW_LONG_CLICKED}</br>
 * <em>Type:</em>{@link #TYPE_VIEW_LONG_CLICKED}</br>
 * <em>Properties:</em></br>
 * <em>Properties:</em></br>
 * <ul>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getText()} - The text of the source.</li>
 *   <li>{@link #getText()} - The text of the source's sub-tree.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #isPassword()} - Whether the source is password.</li>
 *   <li>{@link #isPassword()} - Whether the source is password.</li>
 *   <li>{@link #isChecked()} - Whether the source is checked.</li>
 *   <li>{@link #isChecked()} - Whether the source is checked.</li>
 *   <li>{@link #getContentDescription()} - The content description of the source.</li>
 * </ul>
 * </ul>
 * </p>
 * </p>
 * <p>
 * <p>
@@ -101,16 +105,18 @@ import java.util.List;
 * <em>Type:</em> {@link #TYPE_VIEW_SELECTED}</br>
 * <em>Type:</em> {@link #TYPE_VIEW_SELECTED}</br>
 * <em>Properties:</em></br>
 * <em>Properties:</em></br>
 * <ul>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getText()} - The text of the source.</li>
 *   <li>{@link #getText()} - The text of the source's sub-tree.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #isPassword()} - Whether the source is password.</li>
 *   <li>{@link #isPassword()} - Whether the source is password.</li>
 *   <li>{@link #isChecked()} - Whether the source is checked.</li>
 *   <li>{@link #isChecked()} - Whether the source is checked.</li>
 *   <li>{@link #getItemCount()} - The number of selectable items of the source.</li>
 *   <li>{@link #getItemCount()} - The number of selectable items of the source.</li>
 *   <li>{@link #getCurrentItemIndex()} - The currently selected item index.</li>
 *   <li>{@link #getCurrentItemIndex()} - The currently selected item index.</li>
 *   <li>{@link #getContentDescription()} - The content description of the source.</li>
 * </ul>
 * </ul>
 * </p>
 * </p>
 * <p>
 * <p>
@@ -119,16 +125,18 @@ import java.util.List;
 * <em>Type:</em> {@link #TYPE_VIEW_FOCUSED}</br>
 * <em>Type:</em> {@link #TYPE_VIEW_FOCUSED}</br>
 * <em>Properties:</em></br>
 * <em>Properties:</em></br>
 * <ul>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getText()} - The text of the source.</li>
 *   <li>{@link #getText()} - The text of the source's sub-tree.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #isPassword()} - Whether the source is password.</li>
 *   <li>{@link #isPassword()} - Whether the source is password.</li>
 *   <li>{@link #isChecked()} - Whether the source is checked.</li>
 *   <li>{@link #isChecked()} - Whether the source is checked.</li>
 *   <li>{@link #getItemCount()} - The number of focusable items on the screen.</li>
 *   <li>{@link #getItemCount()} - The number of focusable items on the screen.</li>
 *   <li>{@link #getCurrentItemIndex()} - The currently focused item index.</li>
 *   <li>{@link #getCurrentItemIndex()} - The currently focused item index.</li>
 *   <li>{@link #getContentDescription()} - The content description of the source.</li>
 * </ul>
 * </ul>
 * </p>
 * </p>
 * <p>
 * <p>
@@ -137,6 +145,7 @@ import java.util.List;
 * <em>Type:</em> {@link #TYPE_VIEW_TEXT_CHANGED}</br>
 * <em>Type:</em> {@link #TYPE_VIEW_TEXT_CHANGED}</br>
 * <em>Properties:</em></br>
 * <em>Properties:</em></br>
 * <ul>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
@@ -149,7 +158,17 @@ import java.util.List;
 *   <li>{@link #getAddedCount()} - The number of added characters.</li>
 *   <li>{@link #getAddedCount()} - The number of added characters.</li>
 *   <li>{@link #getRemovedCount()} - The number of removed characters.</li>
 *   <li>{@link #getRemovedCount()} - The number of removed characters.</li>
 *   <li>{@link #getBeforeText()} - The text of the source before the change.</li>
 *   <li>{@link #getBeforeText()} - The text of the source before the change.</li>
 *   <li>{@link #getContentDescription()} - The content description of the source.</li>
 * </ul>
 * </ul>
 * <em>Note:</em> This event type is not dispatched to descendants though
 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
 * source {@link android.view.View} and the sub-tree rooted at it will not receive
 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
 * text content to such events is by setting the
 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
 * view.</br>
 * </p>
 * </p>
 * <p>
 * <p>
 * <b>View text selection changed</b> - represents the event of changing the text
 * <b>View text selection changed</b> - represents the event of changing the text
@@ -157,35 +176,47 @@ import java.util.List;
 * <em>Type:</em> {@link #TYPE_VIEW_TEXT_SELECTION_CHANGED} </br>
 * <em>Type:</em> {@link #TYPE_VIEW_TEXT_SELECTION_CHANGED} </br>
 * <em>Properties:</em></br>
 * <em>Properties:</em></br>
 * <ul>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getText()} - The text of the source.</li>
 *   <li>{@link #getText()} - The text of the source.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #isPassword()} - Whether the source is password.</li>
 *   <li>{@link #isPassword()} - Whether the source is password.</li>
 *   <li>{@link #getFromIndex()} - The selection start index.</li>
 *   <li>{@link #getFromIndex()} - The selection start index.</li>
 *   <li>{@link #getToIndex()} - The selection end index.</li>
 *   <li>{@link #getToIndex()} - The selection end index.</li>
 *   <li>{@link #getItemCount()} - The length of the source text.</li>
 *   <li>{@link #getItemCount()} - The length of the source text.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #getContentDescription()} - The content description of the source.</li>
 * </ul>
 * </ul>
 * <em>Note:</em> This event type is not dispatched to descendants though
 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
 * source {@link android.view.View} and the sub-tree rooted at it will not receive
 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
 * text content to such events is by setting the
 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
 * view.</br>
 * </p>
 * </p>
 * <p>
 * <p>
 * <b>View scrolled</b> - represents the event of scrolling a view. If
 * <b>View scrolled</b> - represents the event of scrolling a view. If
 * the source is a descendant of {@link android.widget.AdapterView} the
 * the source is a descendant of {@link android.widget.AdapterView} the
 * scroll is reported in terms of visible items - the first visible item,
 * scroll is reported in terms of visible items - the first visible item,
 * the last visible item, and the total items - because the the source
 * the last visible item, and the total items - because the the source
 * is unaware if its pixel size since its adapter is responsible for
 * is unaware of its pixel size since its adapter is responsible for
 * creating views. In all other cases the scroll is reported as the current
 * creating views. In all other cases the scroll is reported as the current
 * scroll on the X and Y axis respectively plus the height of the source in
 * scroll on the X and Y axis respectively plus the height of the source in
 * pixels.</br>
 * pixels.</br>
 * <em>Type:</em> {@link #TYPE_VIEW_SCROLLED}</br>
 * <em>Type:</em> {@link #TYPE_VIEW_SCROLLED}</br>
 * <em>Properties:</em></br>
 * <em>Properties:</em></br>
 * <ul>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getText()} - The text of the source.</li>
 *   <li>{@link #getText()} - The text of the source's sub-tree.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #getScrollX()} - The horizontal offset of the source
 *   <li>{@link #getScrollX()} - The horizontal offset of the source
 *                                (without descendants of AdapterView)).</li>
 *                                (without descendants of AdapterView)).</li>
@@ -197,56 +228,165 @@ import java.util.List;
 *                               (for descendants of AdapterView).</li>
 *                               (for descendants of AdapterView).</li>
 *   <li>{@link #getItemCount()} - The total items of the source (for descendants of AdapterView)
 *   <li>{@link #getItemCount()} - The total items of the source (for descendants of AdapterView)
 *                                 or the height of the source in pixels (all other cases).</li>
 *                                 or the height of the source in pixels (all other cases).</li>
 *   <li>{@link #getText()} - Text for providing more context.</li>
 *   <li>{@link #getContentDescription()} - The content description of the source.</li>
 * </ul>
 * </ul>
 * <em>Note:</em> This event type is not dispatched to descendants though
 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
 * source {@link android.view.View} and the sub-tree rooted at it will not receive
 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
 * text content to such events is by setting the
 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
 * view.</br>
 * </p>
 * </p>
 * <p>
 * <p>
 * <b>TRANSITION TYPES</b></br>
 * <b>TRANSITION TYPES</b></br>
 * </p>
 * </p>
 * <p>
 * <b>Window state changed</b> - represents the event of opening a
 * <b>Window state changed</b> - represents the event of opening a
 * {@link android.widget.PopupWindow}, {@link android.view.Menu},
 * {@link android.widget.PopupWindow}, {@link android.view.Menu},
 * {@link android.app.Dialog}, etc.</br>
 * {@link android.app.Dialog}, etc.</br>
 * <em>Type:</em> {@link #TYPE_WINDOW_STATE_CHANGED}</br>
 * <em>Type:</em> {@link #TYPE_WINDOW_STATE_CHANGED}</br>
 * <em>Properties:</em></br>
 * <em>Properties:</em></br>
 * <ul>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getText()} - The text of the source.</li>
 *   <li>{@link #getText()} - The text of the source's sub-tree.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 * </ul>
 * </ul>
 * </p>
 * </p>
 * <p>
 * <p>
 * <b>Window content changed</b> - represents the event of change in the
 * <b>Window content changed</b> - represents the event of change in the
 * content of a window. This change can be adding/removing view, changing
 * content of a window. This change can be adding/removing view, changing
 * a view size, etc.</br>
 * a view size, etc.</br>
 * </p>
 * <p>
 * <p>
 * <strong>Note:</strong> This event is fired only for the window source of the
 * <strong>Note:</strong> This event is fired only for the window source of the
 * last accessibility event different from {@link #TYPE_NOTIFICATION_STATE_CHANGED})
 * last accessibility event different from {@link #TYPE_NOTIFICATION_STATE_CHANGED}
 * and its purpose is to notify clients that the content of the user interaction
 * and its purpose is to notify clients that the content of the user interaction
 * window has changed.
 * window has changed.</br>
 * </p>
 * <em>Type:</em> {@link #TYPE_WINDOW_CONTENT_CHANGED}</br>
 * <em>Type:</em> {@link #TYPE_WINDOW_CONTENT_CHANGED}</br>
 * <em>Properties:</em></br>
 * <em>Properties:</em></br>
 * <ul>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 * </ul>
 * </ul>
 * <em>Note:</em> This event type is not dispatched to descendants though
 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
 * source {@link android.view.View} and the sub-tree rooted at it will not receive
 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
 * text content to such events is by setting the
 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
 * view.</br>
 * </p>
 * <p>
 * <p>
 * <b>NOTIFICATION TYPES</b></br>
 * <b>NOTIFICATION TYPES</b></br>
 * </p>
 * <p>
 * <p>
 * <b>Notification state changed</b> - represents the event showing
 * <b>Notification state changed</b> - represents the event showing
 * {@link android.app.Notification}.
 * {@link android.app.Notification}.</br>
 * <em>Type:</em> {@link #TYPE_NOTIFICATION_STATE_CHANGED}</br>
 * <em>Type:</em> {@link #TYPE_NOTIFICATION_STATE_CHANGED}</br>
 * <em>Properties:</em></br>
 * <em>Properties:</em></br>
 * <ul>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getText()} - The text of the source.</li>
 *   <li>{@link #getText()} - The text of the source's sub-tree.</li>
 *   <li>{@link #getParcelableData()} - The posted {@link android.app.Notification}.</li>
 *   <li>{@link #getParcelableData()} - The posted {@link android.app.Notification}.</li>
 *   <li>{@link #getText()} - Text for providing more context.</li>
 * </ul>
 * </ul>
 * <em>Note:</em> This event type is not dispatched to descendants though
 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
 * source {@link android.view.View} and the sub-tree rooted at it will not receive
 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
 * text content to such events is by setting the
 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
 * view.</br>
 * </p>
 * <p>
 * <b>EXPLORATION TYPES</b></br>
 * </p>
 * <p>
 * <b>View hover enter</b> - represents the event of beginning to hover
 * over a {@link android.view.View}. The hover may be generated via
 * exploring the screen by touch or via a pointing device.</br>
 * <em>Type:</em> {@link #TYPE_VIEW_HOVER_ENTER}</br>
 * <em>Properties:</em></br>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getText()} - The text of the source's sub-tree.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #getContentDescription()} - The content description of the source.</li>
 * </ul>
 * </p>
 * <b>View hover exit</b> - represents the event of stopping to hover
 * over a {@link android.view.View}. The hover may be generated via
 * exploring the screen by touch or via a pointing device.</br>
 * <em>Type:</em> {@link #TYPE_VIEW_HOVER_EXIT}</br>
 * <em>Properties:</em></br>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 *   <li>{@link #getSource()} - The source info (for registered clients).</li>
 *   <li>{@link #getClassName()} - The class name of the source.</li>
 *   <li>{@link #getPackageName()} - The package name of the source.</li>
 *   <li>{@link #getEventTime()}  - The event time.</li>
 *   <li>{@link #getText()} - The text of the source's sub-tree.</li>
 *   <li>{@link #isEnabled()} - Whether the source is enabled.</li>
 *   <li>{@link #getContentDescription()} - The content description of the source.</li>
 * </ul>
 * </p>
 * <p>
 * <b>Touch exploration gesture start</b> - represents the event of starting a touch
 * exploring gesture.</br>
 * <em>Type:</em> {@link #TYPE_TOUCH_EXPLORATION_GESTURE_START}</br>
 * <em>Properties:</em></br>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 * </ul>
 * <em>Note:</em> This event type is not dispatched to descendants though
 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
 * source {@link android.view.View} and the sub-tree rooted at it will not receive
 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
 * text content to such events is by setting the
 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
 * view.</br>
 * </p>
 * <p>
 * <b>Touch exploration gesture end</b> - represents the event of ending a touch
 * exploring gesture.</br>
 * <em>Type:</em> {@link #TYPE_TOUCH_EXPLORATION_GESTURE_END}</br>
 * <em>Properties:</em></br>
 * <ul>
 *   <li>{@link #getEventType()} - The type of the event.</li>
 * </ul>
 * <em>Note:</em> This event type is not dispatched to descendants though
 * {@link android.view.View#dispatchPopulateAccessibilityEvent(AccessibilityEvent)
 * View.dispatchPopulateAccessibilityEvent(AccessibilityEvent)}, hence the event
 * source {@link android.view.View} and the sub-tree rooted at it will not receive
 * calls to {@link android.view.View#onPopulateAccessibilityEvent(AccessibilityEvent)
 * View.onPopulateAccessibilityEvent(AccessibilityEvent)}. The preferred way to add
 * text content to such events is by setting the
 * {@link android.R.styleable#View_contentDescription contentDescription} of the source
 * view.</br>
 * </p>
 * </p>
 * <p>
 * <p>
 * <b>Security note</b>
 * <b>Security note</b>
@@ -254,6 +394,7 @@ import java.util.List;
 * Since an event contains the text of its source privacy can be compromised by leaking
 * Since an event contains the text of its source privacy can be compromised by leaking
 * sensitive information such as passwords. To address this issue any event fired in response
 * sensitive information such as passwords. To address this issue any event fired in response
 * to manipulation of a PASSWORD field does NOT CONTAIN the text of the password.
 * to manipulation of a PASSWORD field does NOT CONTAIN the text of the password.
 * </p>
 *
 *
 * @see android.view.accessibility.AccessibilityManager
 * @see android.view.accessibility.AccessibilityManager
 * @see android.accessibilityservice.AccessibilityService
 * @see android.accessibilityservice.AccessibilityService
+8 −14
Original line number Original line Diff line number Diff line
@@ -881,12 +881,7 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {


    @Override
    @Override
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
        final int eventType = event.getEventType();
        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
        switch (eventType) {
            case AccessibilityEvent.TYPE_VIEW_SCROLLED:
                // Do not populate the text of scroll events.
                return true;
            case AccessibilityEvent.TYPE_VIEW_FOCUSED:
            // This is an exceptional case which occurs when a window gets the
            // This is an exceptional case which occurs when a window gets the
            // focus and sends a focus event via its focused child to announce
            // focus and sends a focus event via its focused child to announce
            // current focus/selection. AdapterView fires selection but not focus
            // current focus/selection. AdapterView fires selection but not focus
@@ -894,7 +889,6 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
            if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
            if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
                event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
                event.setEventType(AccessibilityEvent.TYPE_VIEW_SELECTED);
            }
            }
                break;
        }
        }


        View selectedView = getSelectedView();
        View selectedView = getSelectedView();
+0 −10
Original line number Original line Diff line number Diff line
@@ -371,16 +371,6 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList
        }
        }
    }
    }


    @Override
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
        // Do not append text content to scroll events they are fired frequently
        // and the client has already received another event type with the text.
        if (event.getEventType() != AccessibilityEvent.TYPE_VIEW_SCROLLED) {
            super.dispatchPopulateAccessibilityEvent(event);
        }
        return false;
    }

    /**
    /**
     * Tracks a motion scroll. In reality, this is used to do just about any
     * Tracks a motion scroll. In reality, this is used to do just about any
     * movement to items (touch scroll, arrow-key scroll, set an item as selected).
     * movement to items (touch scroll, arrow-key scroll, set an item as selected).
Loading