From 19d214bd759fbb29228fd82f27a49b631f20d39e Mon Sep 17 00:00:00 2001 From: Jacky Kao Date: Mon, 8 Jun 2020 15:06:00 +0800 Subject: [PATCH] Sending A11y events when a view becomes invisible. Making the A11y event sending to A11y services when a view becomes invisible if the ancestors of this view are all visible, and this view becomes invisible from visible. Bug: 130273130 Test: a11y CTS & unit tests Change-Id: I836d3e34c7a9cba31843d34922b7ba02a8a062f0 --- core/java/android/view/View.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 13f11dce6e4b6..2168fe331972e 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -13800,6 +13800,17 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } } + private void notifySubtreeAccessibilityStateChangedByParentIfNeeded() { + if (!AccessibilityManager.getInstance(mContext).isEnabled()) { + return; + } + + final View sendA11yEventView = (View) getParentForAccessibility(); + if (sendA11yEventView != null && sendA11yEventView.isShown()) { + sendA11yEventView.notifySubtreeAccessibilityStateChangedIfNeeded(); + } + } + /** * Changes the visibility of this View without triggering any other changes. This should only * be used by animation frameworks, such as {@link android.transition.Transition}, where @@ -16229,7 +16240,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback, ((!(mParent instanceof ViewGroup)) || ((ViewGroup) mParent).isShown())) { dispatchVisibilityAggregated(newVisibility == VISIBLE); } - notifySubtreeAccessibilityStateChangedIfNeeded(); + // If this view is invisible from visible, then sending the A11y event by its + // parent which is shown and has the accessibility important. + if ((old & VISIBILITY_MASK) == VISIBLE) { + notifySubtreeAccessibilityStateChangedByParentIfNeeded(); + } else { + notifySubtreeAccessibilityStateChangedIfNeeded(); + } } }