title: Find focusable accessibility nodes in AccessibilityService' AccessibilityEvent
body: <p>I want to extract the views that will get accessibility focus when touch exploration mode of TalkBack would have been used. I want to base this on an <code>AccessibilityEvent</code>. <code>AccessibilityNodeInfo</code> does have the necessary fields, but they do not seem to reflect the correct values.</p>
  <p><a href="https://i.stack.imgur.com/SLTJp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SLTJpl.png" alt="Screenshot with TalkBack focus bounds" /></a></p>
  <p>The screenshot shows 10 views that TalkBack focusses on and pronounces. Each element that gets focus, gets a rectangle drawn on top. I mapped these nodes to JSON for this question.</p>
  <p>Each node has multiple potential fields that could tell me which view gets focus and which view does not. <code>isImportantForAccessibility</code> and <code>actionList</code> are contenders, but there's not a 1 to 1 relationship with the screenshot and the nodes. Also, TalkBack receives an event containing the selected node, so it seems that source code cannot be used to reverse engineer the logic.</p>
  <p><strong>Which fields can tell me TalkBack will focus on that node and pronounce the content?</strong></p>
  <p><em>3 examples that show my investigation, but are not per se needed to understand my question:</em></p>
  <p>For <strong>Files</strong> <code>isVisibleToUser</code> and <code>isImportantForAccessibility</code> are true, so it makes sense to focus and pronounce.</p>
  <pre><code>{
      &quot;actionList&quot;: [
          &quot;ACTION_SELECT&quot;,
          &quot;ACTION_CLEAR_SELECTION&quot;,
          &quot;ACTION_ACCESSIBILITY_FOCUS&quot;,
          &quot;ACTION_NEXT_AT_MOVEMENT_GRANULARITY&quot;,
          &quot;ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY&quot;,
          &quot;ACTION_SET_SELECTION&quot;,
          &quot;ACTION_SHOW_ON_SCREEN&quot;
      ],
      &quot;boundsInScreen&quot;: &quot;44,105,183,193&quot;,
      &quot;className&quot;: &quot;android.widget.TextView&quot;,
      &quot;collectionInfo&quot;: null,
      &quot;collectionItemInfo&quot;: null,
      &quot;contentDescription&quot;: null,
      &quot;isAccessibilityFocused&quot;: false,
      &quot;isFocusable&quot;: false,
      &quot;isFocused&quot;: false,
      &quot;isHeading&quot;: false,
      &quot;isImportantForAccessibility&quot;: true,
      &quot;isVisibleToUser&quot;: true,
      &quot;sourceNodeId&quot;: -4294955806,
      &quot;text&quot;: &quot;Files&quot;,
      &quot;traverseAfterId&quot;: null,
      &quot;traverseBeforeId&quot;: null,
      &quot;children&quot;: []
  }
  </code></pre>
  <p>For <strong>Recent</strong>, there's an <code>LinearLayout</code> with a nested <code>TextView</code>. <code>isVisibleToUser</code> and <code>isImportantForAccessibility</code> are true for both. The <code>LinearLayout</code> does not have a contentDescription and on its own it's not interesting for accessibility but it does get focus. The <code>TextView</code> is interesting, but does not get focus.</p>
  <pre><code>{
      &quot;actionList&quot;: [
          &quot;ACTION_SELECT&quot;,
          &quot;ACTION_CLEAR_SELECTION&quot;,
          &quot;ACTION_CLICK&quot;,
          &quot;ACTION_ACCESSIBILITY_FOCUS&quot;,
          &quot;ACTION_SHOW_ON_SCREEN&quot;
      ],
      &quot;boundsInScreen&quot;: &quot;0,237,770,391&quot;,
      &quot;className&quot;: &quot;android.widget.LinearLayout&quot;,
      &quot;collectionInfo&quot;: null,
      &quot;collectionItemInfo&quot;: {
          &quot;columnIndex&quot;: 0,
          &quot;columnSpan&quot;: 1,
          &quot;isSelected&quot;: false,
          &quot;rowIndex&quot;: 0,
          &quot;rowSpan&quot;: 1
      },
      &quot;contentDescription&quot;: null,
      &quot;isAccessibilityFocused&quot;: false,
      &quot;isFocusable&quot;: false,
      &quot;isFocused&quot;: false,
      &quot;isHeading&quot;: false,
      &quot;isImportantForAccessibility&quot;: true,
      &quot;isVisibleToUser&quot;: true,
      &quot;sourceNodeId&quot;: -4294954792,
      &quot;text&quot;: null,
      &quot;traverseAfterId&quot;: null,
      &quot;traverseBeforeId&quot;: null,
      &quot;children&quot;: [{
          &quot;actionList&quot;: [
              &quot;ACTION_SELECT&quot;,
              &quot;ACTION_CLEAR_SELECTION&quot;,
              &quot;ACTION_ACCESSIBILITY_FOCUS&quot;,
              &quot;ACTION_NEXT_AT_MOVEMENT_GRANULARITY&quot;,
              &quot;ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY&quot;,
              &quot;ACTION_SET_SELECTION&quot;,
              &quot;ACTION_SHOW_ON_SCREEN&quot;
          ],
          &quot;boundsInScreen&quot;: &quot;176,287,748,340&quot;,
          &quot;className&quot;: &quot;android.widget.TextView&quot;,
          &quot;collectionInfo&quot;: null,
          &quot;collectionItemInfo&quot;: null,
          &quot;contentDescription&quot;: null,
          &quot;isAccessibilityFocused&quot;: false,
          &quot;isFocusable&quot;: false,
          &quot;isFocused&quot;: false,
          &quot;isHeading&quot;: false,
          &quot;isImportantForAccessibility&quot;: true,
          &quot;isVisibleToUser&quot;: true,
          &quot;sourceNodeId&quot;: -4294954788,
          &quot;text&quot;: &quot;Recent&quot;,
          &quot;traverseAfterId&quot;: null,
          &quot;traverseBeforeId&quot;: null,
          &quot;children&quot;: []
      }]
  }
  </code></pre>
  <p>Also the divider below Downloads is part of the tree and has <code>isImportantForAccessibility</code> set to true, and can be selected. There is no need to focus on this,  TalkBack doesn't focus on it, but the node seem to say it should be.</p>
  <pre><code>{
      &quot;actionList&quot;: [
          &quot;ACTION_SELECT&quot;,
          &quot;ACTION_CLEAR_SELECTION&quot;,
          &quot;ACTION_ACCESSIBILITY_FOCUS&quot;,
          &quot;ACTION_SHOW_ON_SCREEN&quot;
      ],
      &quot;boundsInScreen&quot;: &quot;0,1161,770,1230&quot;,
      &quot;className&quot;: &quot;android.widget.FrameLayout&quot;,
      &quot;collectionInfo&quot;: null,
      &quot;collectionItemInfo&quot;: {
          &quot;columnIndex&quot;: 0,
          &quot;columnSpan&quot;: 1,
          &quot;isSelected&quot;: false,
          &quot;rowIndex&quot;: 6,
          &quot;rowSpan&quot;: 1
      },
      &quot;contentDescription&quot;: null,
      &quot;isAccessibilityFocused&quot;: false,
      &quot;isFocusable&quot;: false,
      &quot;isFocused&quot;: false,
      &quot;isHeading&quot;: false,
      &quot;isImportantForAccessibility&quot;: true,
      &quot;isVisibleToUser&quot;: true,
      &quot;sourceNodeId&quot;: -4294954732,
      &quot;text&quot;: null,
      &quot;traverseAfterId&quot;: null,
      &quot;traverseBeforeId&quot;: null,
      &quot;children&quot;: []
  }
  </code></pre>
  <p>For completeness, the xml used of the AccessibilityService:</p>
  <pre><code>&lt;accessibility-service xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:accessibilityEventTypes=&quot;typeWindowStateChanged|typeWindowContentChanged&quot;
      android:accessibilityFeedbackType=&quot;feedbackVisual&quot;
      android:accessibilityFlags=&quot;flagDefault&quot;
      android:canRetrieveWindowContent=&quot;true&quot; /&gt;
  </code></pre>
  <p>I used an emulator with API 31 to get the tree.</p>