1

In my application I have an accessibility service that gets the root of the active window before performing further actions. The relevant section looks like this:

    @Override
    public final void onAccessibilityEvent(AccessibilityEvent event) {
    ...
    AccessibilityNodeInfo rootAccessibilityNode = getRootInActiveWindow();
    ...
    }

I'm getting complaints from users about ANRs, and the stacktrace is pointing me towards the getRootInActiveWindow line.

Is it possible that getRootInActiveWindow causes ANRs and if so, what is the mechanism? Does this method need to be called in it's own thread? There's nothing in the documentation about this.

Jon
  • 7,941
  • 9
  • 53
  • 105

1 Answers1

1

I doubt very much that this line is the direct cause of the crash, still want to see a Stack Trace. It would also be helpful to know how you launch your service (developers new to accessibility services frequently get this wrong). Assuming you've done your homework on the usual obvious answers, we're left with the following:

A: Permissions issues. If you've done your testing on rooted devices or whatever, it may be that you're users are having permissions issues. Insure that you have android:canRetrieveWindowContent="true" in your service confix XML file.

B: If you have not filtered out any accessibility events, there are events that trigger between window loads and such. It may be that your attempting to grab onto content that is not there and the system doesn't like it. This could also be hidden by doing testing on emulators, as it could be a race condition, that does not manifest itself in the slower emulated environment. This would also cause performance issues, as the node hierarchy is a reasonably expensive thing to traverse through and you wouldn't want to do so frequently. Try limiting the accessibilityEventTypes that you have your code run on.

MobA11y
  • 18,425
  • 3
  • 49
  • 76
  • android:canRetrieveWindowContent="true" is already in my service confix XML file & accessibilityEventTypes used by me is "typeWindowStateChanged , typeViewFocused ,typeWindowContentChanged". still getting lot of ANR due to getRootInActiveWindow. mostly in Android 8.0 – Nikhil Oct 23 '17 at 04:23
  • If you have an ANR you have a stacktrace... you should ask a quesiton, and share said stracktrace. – MobA11y Oct 23 '17 at 15:01
  • 1
    Thanks for your kind reply. Please check https://stackoverflow.com/questions/46789325/getting-lots-of-anr-due-to-accessibilitynodeinfo-getchild?noredirect=1#comment80712488_46789325 – Nikhil Oct 23 '17 at 17:34