Fixing some accessibility bugs.
1. Views not important for accessibility should not send events. 2. The base View implementation should not add it self to the list of children for accessibility. 3. Null pointer exception in AccessibilityNodeInfoCache. Change-Id: Ie5b373362269200ead13ffe632679bd42ee40309
This commit is contained in:
@@ -5022,7 +5022,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
* @param text The announcement text.
|
||||
*/
|
||||
public void announceForAccessibility(CharSequence text) {
|
||||
if (AccessibilityManager.getInstance(mContext).isEnabled() && mParent != null) {
|
||||
if (AccessibilityManager.getInstance(mContext).isEnabled() && mParent != null
|
||||
&& isImportantForAccessibility()) {
|
||||
AccessibilityEvent event = AccessibilityEvent.obtain(
|
||||
AccessibilityEvent.TYPE_ANNOUNCEMENT);
|
||||
onInitializeAccessibilityEvent(event);
|
||||
@@ -5072,7 +5073,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
* Note: Called from the default {@link AccessibilityDelegate}.
|
||||
*/
|
||||
void sendAccessibilityEventUncheckedInternal(AccessibilityEvent event) {
|
||||
if (!isShown()) {
|
||||
if (!isShown() || !isImportantForAccessibility()) {
|
||||
return;
|
||||
}
|
||||
onInitializeAccessibilityEvent(event);
|
||||
@@ -7372,9 +7373,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
* @param children The list of children for accessibility.
|
||||
*/
|
||||
public void addChildrenForAccessibility(ArrayList<View> children) {
|
||||
if (includeForAccessibility()) {
|
||||
children.add(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -7388,7 +7387,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
* @hide
|
||||
*/
|
||||
public boolean includeForAccessibility() {
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (mAttachInfo != null) {
|
||||
return (mAttachInfo.mAccessibilityFetchFlags
|
||||
& AccessibilityNodeInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS) != 0
|
||||
|
||||
@@ -174,11 +174,13 @@ public class AccessibilityNodeInfoCache {
|
||||
// subtrees in the cache.
|
||||
// TODO: Runs in O(n^2), could optimize to O(n + n log n)
|
||||
final LongArray newChildrenIds = info.getChildNodeIds();
|
||||
final int oldChildCount = oldInfo.getChildCount();
|
||||
for (int i = 0; i < oldChildCount; i++) {
|
||||
final long oldChildId = oldInfo.getChildId(i);
|
||||
if (newChildrenIds.indexOf(oldChildId) < 0) {
|
||||
clearSubTreeLocked(oldChildId);
|
||||
if (newChildrenIds != null) {
|
||||
final int oldChildCount = oldInfo.getChildCount();
|
||||
for (int i = 0; i < oldChildCount; i++) {
|
||||
final long oldChildId = oldInfo.getChildId(i);
|
||||
if (newChildrenIds.indexOf(oldChildId) < 0) {
|
||||
clearSubTreeLocked(oldChildId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user