From a88ee6f588271b0ebc06284cc9a276ebc2ad214c Mon Sep 17 00:00:00 2001 From: Jackal Guo Date: Tue, 11 Feb 2020 14:20:16 +0800 Subject: [PATCH] Adjust the logic of isImportantForAccessibility According to the logic in #isImportantForAccessibility, SurfaceView wouldn't be important by default. This results in the A11yNodeInfo generated by this SurfaceView isn't important. If this SurfaceView hosts an embedded hierarchy, the accessibility services may ignore it. Hence, it couldn't compose the complete node tree. Bug: 149266686 Test: a11y CTS & unit tests Change-Id: I90d9f043339d2ad72607e8ae8c8dfc2c1b0f004d --- core/java/android/view/SurfaceView.java | 13 +++++++++++++ core/java/android/view/View.java | 3 +-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 5566e0e4292ee..2b11889334d85 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -1596,6 +1596,19 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall info.addChild(wrapper.getLeashToken()); } + @Override + public int getImportantForAccessibility() { + final int mode = super.getImportantForAccessibility(); + // If developers explicitly set the important mode for it, don't change the mode. + // Only change the mode to important when this SurfaceView isn't explicitly set and has + // an embedded hierarchy. + if (mRemoteAccessibilityEmbeddedConnection == null + || mode != IMPORTANT_FOR_ACCESSIBILITY_AUTO) { + return mode; + } + return IMPORTANT_FOR_ACCESSIBILITY_YES; + } + private void initEmbeddedHierarchyForAccessibility(SurfaceControlViewHost.SurfacePackage p) { final IAccessibilityEmbeddedConnection connection = p.getAccessibilityEmbeddedConnection(); final RemoteAccessibilityEmbeddedConnection wrapper = diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index b9be33ca0f59f..5136ba1049a7f 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -13429,8 +13429,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * @see #getImportantForAccessibility() */ public boolean isImportantForAccessibility() { - final int mode = (mPrivateFlags2 & PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_MASK) - >> PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT; + final int mode = getImportantForAccessibility(); if (mode == IMPORTANT_FOR_ACCESSIBILITY_NO || mode == IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) { return false;