From 9af1378c82c2e39c40383af117c568257152eee9 Mon Sep 17 00:00:00 2001 From: Eugene Susla Date: Thu, 22 Mar 2018 16:29:10 -0700 Subject: [DO NOT MERGE] Avoid sending content changed a11y events from wrong views The root cause of both attached bugs was the tree-merging algorithm in ViewRootImpl.SendWindowContentChangedAccessibilityEvent converging on a common predecessor that is marked not View#isImportantForAccessibility. As a result, such unlucky content changed events were discarded. Fixes: 72378611, 72950579 Test: ensure attached bugs are fixed Change-Id: I3c3c66151b6cd4773de4eadd417709e9a61a7cf2 (cherry picked from commit 3fb3c590400ae7bcc9bc7d5baba5a29678f9e873) --- core/java/android/view/View.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'core/java/android/view/View.java') diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index dc58f11e83fd..b367dc7b9c50 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -11791,6 +11791,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback, return null; } + /** @hide */ + View getSelfOrParentImportantForA11y() { + if (isImportantForAccessibility()) return this; + ViewParent parent = getParentForAccessibility(); + if (parent instanceof View) return (View) parent; + return null; + } + /** * Adds the children of this View relevant for accessibility to the given list * as output. Since some Views are not important for accessibility the added @@ -15006,10 +15014,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, public void setAlpha(@FloatRange(from=0.0, to=1.0) float alpha) { ensureTransformationInfo(); if (mTransformationInfo.mAlpha != alpha) { - // Report visibility changes, which can affect children, to accessibility - if ((alpha == 0) ^ (mTransformationInfo.mAlpha == 0)) { - notifySubtreeAccessibilityStateChangedIfNeeded(); - } + float oldAlpha = mTransformationInfo.mAlpha; mTransformationInfo.mAlpha = alpha; if (onSetAlpha((int) (alpha * 255))) { mPrivateFlags |= PFLAG_ALPHA_SET; @@ -15021,6 +15026,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, invalidateViewProperty(true, false); mRenderNode.setAlpha(getFinalAlpha()); } + // Report visibility changes, which can affect children, to accessibility + if ((alpha == 0) ^ (oldAlpha == 0)) { + notifySubtreeAccessibilityStateChangedIfNeeded(); + } } } -- cgit v1.2.3