From 6dde7e75e88420a89c09b303417593590e6ad6d5 Mon Sep 17 00:00:00 2001 From: Phil Weaver Date: Tue, 26 Apr 2016 17:01:29 -0700 Subject: [PATCH] Fix crash with a11y set text with text filters. A text filter may shorten the text, so we need to use the text that's actually in the View, not the text we requested, to move the selection. Also removing the override of performAccessibilityActionInternal, which should have been done as part of adding text actions initially. Bug: 28253708 Change-Id: I184f49dcba0238f4ccc222597cefca258393b263 --- core/java/android/widget/EditText.java | 22 ---------------------- core/java/android/widget/TextView.java | 7 +++++-- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/core/java/android/widget/EditText.java b/core/java/android/widget/EditText.java index ad355504a0ee..24d861843a13 100644 --- a/core/java/android/widget/EditText.java +++ b/core/java/android/widget/EditText.java @@ -149,26 +149,4 @@ public class EditText extends TextView { info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SET_TEXT); } } - - /** @hide */ - @Override - public boolean performAccessibilityActionInternal(int action, Bundle arguments) { - switch (action) { - case AccessibilityNodeInfo.ACTION_SET_TEXT: { - if (!isEnabled()) { - return false; - } - CharSequence text = (arguments != null) ? arguments.getCharSequence( - AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE) : null; - setText(text); - if (text != null && text.length() > 0) { - setSelection(text.length()); - } - return true; - } - default: { - return super.performAccessibilityActionInternal(action, arguments); - } - } - } } diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 48fd58b219db..01e657c078e5 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -9202,8 +9202,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener CharSequence text = (arguments != null) ? arguments.getCharSequence( AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE) : null; setText(text); - if (text != null && text.length() > 0) { - Selection.setSelection((Spannable) mText, text.length()); + if (mText != null) { + int updatedTextLength = mText.length(); + if (updatedTextLength > 0) { + Selection.setSelection((Spannable) mText, updatedTextLength); + } } } return true; default: { -- 2.11.0