Reduce extra a11y events when alpha changes.

Changes in alpha only matter if they affect visibility,
so only 0 <-> nonzero changes are worth reporting. Report
them as subtree changes, as visibility affects subviews.

Not reporting every change greatly reduces the number of
event reported when alpha is animated.

Bug: 30183085
Change-Id: I905d53aa81ca8248b3aed86a91842ef499f303a8
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index e648114..d53d69b 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -12303,6 +12303,10 @@
     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();
+            }
             mTransformationInfo.mAlpha = alpha;
             if (onSetAlpha((int) (alpha * 255))) {
                 mPrivateFlags |= PFLAG_ALPHA_SET;
@@ -12313,8 +12317,6 @@
                 mPrivateFlags &= ~PFLAG_ALPHA_SET;
                 invalidateViewProperty(true, false);
                 mRenderNode.setAlpha(getFinalAlpha());
-                notifyViewAccessibilityStateChangedIfNeeded(
-                        AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED);
             }
         }
     }