diff options
| author | 2018-12-27 19:56:54 +0800 | |
|---|---|---|
| committer | 2019-01-07 10:31:42 +0800 | |
| commit | 0b5ca24a41ec6fe7fe34583cbb7871886f6bf25e (patch) | |
| tree | ab69b8eb079dd53a156dd1543dae817327f9cff7 | |
| parent | 394b0d1a0405e3909633962e3145dca81b442f82 (diff) | |
Avoid adding node itself as child node.
Apps can call addChild through AccessibilityNodeProvider, so it's
possible that an app adds a node itself as a child node. This will break
down the integrity of UI tree and cause failure to operation in
UIAutomator. Thus I suggest do this integrity check when adding child.
Test: as follows
    - built
    - flashed
    - booted
    - run my test script based on uiautomator
Change-Id: I8cba22a1d9d1a49365c6bce4241ef5067502fb79
Signed-off-by: qinyige <qinyige@xiaomi.com>
| -rw-r--r-- | core/java/android/view/accessibility/AccessibilityNodeInfo.java | 10 | 
1 files changed, 10 insertions, 0 deletions
| diff --git a/core/java/android/view/accessibility/AccessibilityNodeInfo.java b/core/java/android/view/accessibility/AccessibilityNodeInfo.java index 158ac6b0cdb5..28550ee61fbb 100644 --- a/core/java/android/view/accessibility/AccessibilityNodeInfo.java +++ b/core/java/android/view/accessibility/AccessibilityNodeInfo.java @@ -40,6 +40,7 @@ import android.text.style.AccessibilityURLSpan;  import android.text.style.ClickableSpan;  import android.text.style.URLSpan;  import android.util.ArraySet; +import android.util.Log;  import android.util.LongArray;  import android.util.Pools.SynchronizedPool;  import android.view.View; @@ -85,6 +86,8 @@ public class AccessibilityNodeInfo implements Parcelable {      private static final boolean DEBUG = false; +    private static final String TAG = "AccessibilityNodeInfo"; +      /** @hide */      public static final int UNDEFINED_CONNECTION_ID = -1; @@ -990,6 +993,7 @@ public class AccessibilityNodeInfo implements Parcelable {       * <strong>Note:</strong> Cannot be called from an       * {@link android.accessibilityservice.AccessibilityService}.       * This class is made immutable before being delivered to an AccessibilityService. +     * Note that a view cannot be made its own child.       * </p>       *       * @param child The child. @@ -1037,6 +1041,7 @@ public class AccessibilityNodeInfo implements Parcelable {       * hierarchy for accessibility purposes. This enables custom views that draw complex       * content to report them selves as a tree of virtual views, thus conveying their       * logical structure. +     * Note that a view cannot be made its own child.       * </p>       *       * @param root The root of the virtual subtree. @@ -1054,6 +1059,11 @@ public class AccessibilityNodeInfo implements Parcelable {          final int rootAccessibilityViewId =              (root != null) ? root.getAccessibilityViewId() : UNDEFINED_ITEM_ID;          final long childNodeId = makeNodeId(rootAccessibilityViewId, virtualDescendantId); +        if (childNodeId == mSourceNodeId) { +            Log.e(TAG, "Rejecting attempt to make a View its own child"); +            return; +        } +          // If we're checking uniqueness and the ID already exists, abort.          if (checked && mChildNodeIds.indexOf(childNodeId) >= 0) {              return; |