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

Commit 72fde85f authored by Phil Weaver's avatar Phil Weaver
Browse files

Remove unusable a11y APIs for ClickableSpans.

This change essentially backs out ag/683646, which added an API to click
on ClickableSpans within a TextView. This API has the flaw, however,
that ClickableSpans are not parcelable, so they are not in general
reported to AccessibilityServices. That means that services will have no
idea what they are activating.

Since the API is not usable end-to-end, I'm backing it out before the
API is final.

Bug: 17726921
Change-Id: I541c6218f2899ff67a6b32a13fd9ae6f3b53b3c4
parent 13af9845
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -20325,8 +20325,8 @@ package android.media {
  public class MediaActionSound {
    ctor public MediaActionSound();
    method public synchronized void load(int);
    method public synchronized void play(int);
    method public void load(int);
    method public void play(int);
    method public void release();
    field public static final int FOCUS_COMPLETE = 1; // 0x1
    field public static final int SHUTTER_CLICK = 0; // 0x0
@@ -44089,8 +44089,6 @@ package android.view.accessibility {
    method public void setVisibleToUser(boolean);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int ACTION_ACCESSIBILITY_FOCUS = 64; // 0x40
    field public static final java.lang.String ACTION_ARGUMENT_CLICK_CHARACTER_INDEX_INT = "android.view.accessibility.action.ARGUMENT_CLICK_CHARACTER_INDEX_INT";
    field public static final java.lang.String ACTION_ARGUMENT_CLICK_SPAN_INDEX_INT = "android.view.accessibility.action.ARGUMENT_CLICK_SPAN_INDEX_INT";
    field public static final java.lang.String ACTION_ARGUMENT_COLUMN_INT = "android.view.accessibility.action.ARGUMENT_COLUMN_INT";
    field public static final java.lang.String ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN = "ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN";
    field public static final java.lang.String ACTION_ARGUMENT_HTML_ELEMENT_STRING = "ACTION_ARGUMENT_HTML_ELEMENT_STRING";
+2 −4
Original line number Diff line number Diff line
@@ -21804,8 +21804,8 @@ package android.media {
  public class MediaActionSound {
    ctor public MediaActionSound();
    method public synchronized void load(int);
    method public synchronized void play(int);
    method public void load(int);
    method public void play(int);
    method public void release();
    field public static final int FOCUS_COMPLETE = 1; // 0x1
    field public static final int SHUTTER_CLICK = 0; // 0x0
@@ -46832,8 +46832,6 @@ package android.view.accessibility {
    method public void setVisibleToUser(boolean);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int ACTION_ACCESSIBILITY_FOCUS = 64; // 0x40
    field public static final java.lang.String ACTION_ARGUMENT_CLICK_CHARACTER_INDEX_INT = "android.view.accessibility.action.ARGUMENT_CLICK_CHARACTER_INDEX_INT";
    field public static final java.lang.String ACTION_ARGUMENT_CLICK_SPAN_INDEX_INT = "android.view.accessibility.action.ARGUMENT_CLICK_SPAN_INDEX_INT";
    field public static final java.lang.String ACTION_ARGUMENT_COLUMN_INT = "android.view.accessibility.action.ARGUMENT_COLUMN_INT";
    field public static final java.lang.String ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN = "ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN";
    field public static final java.lang.String ACTION_ARGUMENT_HTML_ELEMENT_STRING = "ACTION_ARGUMENT_HTML_ELEMENT_STRING";
+2 −4
Original line number Diff line number Diff line
@@ -20390,8 +20390,8 @@ package android.media {
  public class MediaActionSound {
    ctor public MediaActionSound();
    method public synchronized void load(int);
    method public synchronized void play(int);
    method public void load(int);
    method public void play(int);
    method public void release();
    field public static final int FOCUS_COMPLETE = 1; // 0x1
    field public static final int SHUTTER_CLICK = 0; // 0x0
@@ -44163,8 +44163,6 @@ package android.view.accessibility {
    method public void setVisibleToUser(boolean);
    method public void writeToParcel(android.os.Parcel, int);
    field public static final int ACTION_ACCESSIBILITY_FOCUS = 64; // 0x40
    field public static final java.lang.String ACTION_ARGUMENT_CLICK_CHARACTER_INDEX_INT = "android.view.accessibility.action.ARGUMENT_CLICK_CHARACTER_INDEX_INT";
    field public static final java.lang.String ACTION_ARGUMENT_CLICK_SPAN_INDEX_INT = "android.view.accessibility.action.ARGUMENT_CLICK_SPAN_INDEX_INT";
    field public static final java.lang.String ACTION_ARGUMENT_COLUMN_INT = "android.view.accessibility.action.ARGUMENT_COLUMN_INT";
    field public static final java.lang.String ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN = "ACTION_ARGUMENT_EXTEND_SELECTION_BOOLEAN";
    field public static final java.lang.String ACTION_ARGUMENT_HTML_ELEMENT_STRING = "ACTION_ARGUMENT_HTML_ELEMENT_STRING";
+0 −57
Original line number Diff line number Diff line
@@ -327,36 +327,6 @@ public class AccessibilityNodeInfo implements Parcelable {

    // Action arguments

    /**
     * Argument for specifying index of {@link android.text.style.ClickableSpan} the click action is
     * related to.
     * <p>
     * <strong>Type:</strong> int<br>
     * <strong>Actions:</strong>
     * {@link AccessibilityAction#ACTION_CLICK}
     * </p>
     *
     * @see AccessibilityAction#ACTION_CLICK
     */
    public static final String ACTION_ARGUMENT_CLICK_SPAN_INDEX_INT =
            "android.view.accessibility.action.ARGUMENT_CLICK_SPAN_INDEX_INT";

    /**
     * Argument for specifying index of character in the text which contains
     * {@link android.text.style.ClickableSpan} the click action is
     * related to. If there is more than one {@link android.text.style.ClickableSpan} assigned for
     * the range the character is in only the first span would be clicked.
     * <p>
     * <strong>Type:</strong> int<br>
     * <strong>Actions:</strong>
     * {@link AccessibilityAction#ACTION_CLICK}
     * </p>
     *
     * @see AccessibilityAction#ACTION_CLICK
     */
    public static final String ACTION_ARGUMENT_CLICK_CHARACTER_INDEX_INT =
            "android.view.accessibility.action.ARGUMENT_CLICK_CHARACTER_INDEX_INT";

    /**
     * Argument for which movement granularity to be used when traversing the node text.
     * <p>
@@ -3391,33 +3361,6 @@ public class AccessibilityNodeInfo implements Parcelable {

        /**
         * Action that clicks on the node info.
         *
         * <p>
         * If a specific {@link android.text.style.ClickableSpan} within node's text content is
         * supposed to be clicked, then one of {@link #ACTION_ARGUMENT_CLICK_SPAN_INDEX_INT} or
         * {@link #ACTION_ARGUMENT_CLICK_CHARACTER_INDEX_INT} arguments should be specified.
         * If both arguments are set {@link #ACTION_ARGUMENT_CLICK_CHARACTER_INDEX_INT} would
         * be ignored.<br>
         *
         * {@link #ACTION_ARGUMENT_CLICK_SPAN_INDEX_INT} specifies index of corresponding
         * {@link android.text.style.ClickableSpan} in {@link android.text.SpannableString}.<br>
         *
         * {@link #ACTION_ARGUMENT_CLICK_CHARACTER_INDEX_INT} specifies index of character
         * that could contain one or more spans.
         * </p>
         *
         * <p>
         * <strong>Optional arguments:</strong>
         * {@link #ACTION_ARGUMENT_CLICK_SPAN_INDEX_INT},
         * {@link #ACTION_ARGUMENT_CLICK_CHARACTER_INDEX_INT}<br>
         * <strong>Example:</strong> Perform click on 3rd {@link android.text.style.ClickableSpan}
         * inside {@link android.text.SpannableString} in node's text.
         * <code><pre><p>
         *   Bundle arguments = new Bundle();
         *   arguments.putInt(AccessibilityNodeInfo.ACTION_ARGUMENT_CLICK_SPAN_INDEX_INT, 3);
         *   info.performAction(AccessibilityAction.ACTION_CLICK.getId(), arguments);
         * </code></pre></p>
         * </p>
         */
        public static final AccessibilityAction ACTION_CLICK =
                new AccessibilityAction(
+1 −41
Original line number Diff line number Diff line
@@ -9247,52 +9247,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener

    private boolean performAccessibilityActionClick(Bundle arguments) {
        boolean handled = false;
        boolean processed = false;

        if (!isEnabled()) {
            return false;
        }

        if (arguments != null && arguments.containsKey(
                AccessibilityNodeInfo.ACTION_ARGUMENT_CLICK_SPAN_INDEX_INT)) {
            int spanIndex = arguments.getInt(
                    AccessibilityNodeInfo.ACTION_ARGUMENT_CLICK_SPAN_INDEX_INT, -1);
            if (spanIndex >= 0 && hasSpannableText()) {
                ClickableSpan[] spans = ((Spannable) mText).getSpans(0,
                        mText.length(), ClickableSpan.class);
                if (spans != null && spans.length > spanIndex && spans[spanIndex] != null) {
                    // Simulate View.onTouchEvent for an ACTION_UP event
                    if (isFocusable() && !isFocused()) {
                        requestFocus();
                    }
                    spans[spanIndex].onClick(this);
                    handled = true;
                }
            }
            processed = true;
        }

        if (!processed && arguments != null &&  arguments.containsKey(
                AccessibilityNodeInfo.ACTION_ARGUMENT_CLICK_CHARACTER_INDEX_INT)) {
            int characterIndex = arguments.getInt(
                    AccessibilityNodeInfo.ACTION_ARGUMENT_CLICK_CHARACTER_INDEX_INT, -1);
            if (characterIndex >= 0 && hasSpannableText()) {
                ClickableSpan[] spans = ((Spannable) mText).getSpans(characterIndex,
                        characterIndex, ClickableSpan.class);
                // click only on the first span to keep parity with onTouch() implementation
                if (spans != null && spans.length > 0 && spans[0] != null) {
                    // Simulate View.onTouchEvent for an ACTION_UP event
                    if (isFocusable() && !isFocused()) {
                        requestFocus();
                    }
                    spans[0].onClick(this);
                    handled = true;
                }
            }
            processed = true;
        }

        if (!processed && (isClickable() || isLongClickable())) {
        if (isClickable() || isLongClickable()) {
            // Simulate View.onTouchEvent for an ACTION_UP event
            if (isFocusable() && !isFocused()) {
                requestFocus();